注释
‘’’
ctrl + / 快捷注释
多行注释""" “”"或’’’ ‘’’
‘’’
‘’’
def print(self, *args, sep=’ ‘, end=’\n’, file=None): # known special case of print
“”"
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
“”"
def 代表函数
print 可以打印多个值 逗号分隔
print(‘hello’,‘python’)
也可以打印空值
print( )
输入函数 input
在进程中等待输入
可以输出字符串
input(‘请输入:’)
等号 =
用于把右边赋值给左边
‘’’
string = input(‘请输入:’)
print(string)
‘’’
变量声明
使用type 和 print 查询变量类型
1.字符串
字符串的格式 '或"没区别
切片和取值
str1 = ‘i love python123’
如何只打印python
通过 下标 切片 的方法
取一位 print(str1[0])
python 遵循c++ 左闭右开 [ )
取前三位 print(str1[0:3])
取后三位
print(str1[13:16])
print(str1[13:])
print(str1[-3:])
取所有
print(str[:])
每1位取1位 就是都取
print(str1[::1])
每2位取1位 就是 lo 取第一个
print(str1[::2])
逆序
print(str1[::-1])
切片和取值总结:
str1[起始位置:结束位置:步长]
步长为正 从左往右取
步长为负 从右往左取
‘’’