首页 > 编程语言 >Python官方文档学习笔记

Python官方文档学习笔记

时间:2023-03-29 22:25:05浏览次数:51  
标签:Hostname usage Python hostname 笔记 Usage 文档 print

原文:https://docs.python.org/3/tutorial/introduction.html
版本:3.11.2

Using Python as a Calculator

Numbers

  • Division (/) always returns a float.
  • To do floor division and get an integer result you can use the // operator;
  • To calculate the remainder you can use %
  • With Python, it is possible to use the ** operator to calculate powers
4/2
Out[2]: 2.0
4//2
Out[3]: 2
5 % 2
Out[4]: 1
2 ** 3
Out[5]: 8
  • In interactive mode, the last printed expression is assigned to the variable _. This means that when you are using Python as a desk calculator, it is somewhat easier to continue calculations, for example:
>>> 4/2
2.0
>>> _ + 1
3.0

Strings

  • \ can be used to escape quotes 转义字符: \ !
>>> "doesn\'t"
"doesn't"
>>> '"doesn\'t"'
'"doesn\'t"'
  • ''单引号内套双引号,可以使转义字符失效;但print()会删掉外侧的单引号,又使得转义字符生效
>>> '"Isn\'t," they said.'
'"Isn\'t," they said.'
>>> print('"Isn\'t," they said.')
"Isn't," they said.
  • Raw strings
>>> print('C:\some\name')  # \n被识别为换行符
C:\some
ame
>>> print(r'C:\some\name')  # 在括号外面加上r可以打印出原字符
C:\some\name
>>> print("""\
... Usage: thingy [OPTIONS]
...      -h                        Display this usage message
...      -H hostname               Hostname to connect to
... """)
Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to

>>> print("""\
    Usage: thingy [OPTIONS]
         -h                        Display this usage message
         -H hostname               Hostname to connect to
    \""")

Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to

标签:Hostname,usage,Python,hostname,笔记,Usage,文档,print
From: https://www.cnblogs.com/lsysnote/p/17270662.html

相关文章

  • 解决pip命令无法执行Python问题Unable to create process using...
    解决方法删除:Python37\Lib\site-packages\pip-19.1.dist-info删除:Python37\Scripts\pip*.exe(所有pip开头的)安装:python-mpipinstall--upgradepip......
  • [Python3]SM3国密算法
    fromgmsslimportsm4,sm3defsm3_hash(message:str):"""国密sm3加密:parammessage:消息值,bytes类型:return:哈希值"""msg_l......
  • 阅读笔记2
    《构建之法》第二章讲的是个人的技术和流程,第二章首先看到的是让我很找不到头绪的,单元测试,不知道怎么去测试,不知道测试有什意思。为什么要测试,程序写好了运行一下能运行一......
  • Python errors All In One
    PythonerrorsAllInOneerrors❌from:can'tread/var/mail/gpiozerohttps://stackoverflow.com/questions/16069816/getting-python-error-from-cant-read-var-m......
  • [Request对象] 笔记
    Servlet的继承体系Tomcat需要解析请求数据,封装为request对象,并且创建request对象传递到service方法中使用request对象,查阅JavaEEAPI文档的HttpServletRequest接口re......
  • 分布式学习笔记-zookeeper以及kafka
    zookeeper所谓分布式系统就是在不同的地域分布的多个服务器,共同组成一个应用系统来为用户提供服务,在分布式系统中最重要的是进程调度。多个进程的应用需要竞争资源,此时需要......
  • Python 学习12 网络编程
    P160Socket服务端开发......
  • Python ThreadPoolExecutor的简单使用
    pythonThreadPoolExecutor的简单使用一、前言Python3.2以后,官方新增了concurrent.futures模块,该模块提供线程池ThreadPoolExecutor和进程池ProcessPoolExecutor。使用......
  • 全网最详细中英文ChatGPT-GPT-4示例文档-表格智能生成从0到1快速入门——官网推荐的48
    目录Introduce简介setting设置Prompt提示Sampleresponse回复样本APIrequest接口请求python接口请求示例node.js接口请求示例curl命令示例json格式示例其它资料下载......
  • Python-OPCUA 读写西门子PLC设备的数据
    Python版本:3.9在python中,通过opcua通讯方式向PLC中读写数据1.安装opcua首先安装一下opcua:pipinstallopcua2.实现与PLC的交互我们可以通过导入文件的方式,实现pl......