##basic of python##
##2018/4/3##
##point1
print('##point1')
##注释
#注释是任何存在于 # 右侧的文字,主要作用是写给程序读者看的笔记
#e.g.1
print('hello world')#you should know that print is a function
#or maybe like this
#you should know that print is a function
print('hello world')
##point2
print('##point2')
##字面常量 Literal Constants
#字面常量是例如 2,3.5,-10086这样的数字或者 hello world 这样的字符串
##point3
print('##point3')
##数字
#数字主要分为两类----整数(Integers)与浮点数(Floats)
#整数就比如2,-10086这样的数字,他跟数学中的整数概念一致
#浮点数类似于小数,有多种表示形式:比如1.23456或者.123456e1,两者表示同一数据
##point4
print('##point4')
##字符串
##一串字符串string是字符characters的序列sequence
##单引号,你可以使用单引号来指定字符串
##e.g.2
str_1 = 'hello world'#所有引号内的空间,空格、制表、回车等都会原样保留
print(str_1)
##双引号 = 单引号
##三引号
##你可以使用三引号来制定多行字符串。你可以在三引号之间自由的使用单引号与双引号
##e.g.3
str_2 = '''
this is the first line
"this is the second line"
'''
print(str_2)
##字符串是不可变的
##point5
print('##point5')
##格式化输出 format()
##e.g.4
country = 'China'
age = 20
print('I am coming form {0} and I am {1} years old.'.format(country,age))
#这样写也是可以的
print('I am coming form {} and I am {} years old.'.format(country,age))
#其实format方法所做的事情便是将每个参数值替换至格式所在的位置。这其中有更详细的格式
##e.g.5
#对于浮点数0.333保留小数点后三位
print('{}'.format(1/3))
print('{:0.3f}'.format(1/3))
#使用下划线填充文本,并保持文字处于中间位置
#使用 ^ 定义string字符串长度
print('{:_^11}'.format('hello'))
#基于关键词输出
print('I am coming form {country} and I am {age} years old.'.format(country='China',age='20'))
#另外还要注意一点
#print总会以一个不可见的换行符'\n'结尾
#为了防止这种效果,可以通过end指定其应以空白结尾
print('a',end=' ')
print('b')
print('c',end='')
print('d')
##point6
##转义序列
## \' 输出单引号
## \" 输出双引号
## \\ 输出反斜杠
## \n 换行
## \t 制表
##e.g.6
print("What's your name?")
print('What\'s your name?')
print('a\tb\nc\td')
#这种方式会让下一个输出继续在本行进行
print('This is the first sentence.\
This is the second sentence.')
##point7
##变量 Veriables
#Python变量有一定的命名规则
变量=1
print(变量)
##point8
##数据类型
##point9
##对象
##Python将程序中的任何内容统称为对象Object
Byte of Python------Basic of Python
最新推荐文章于 2022-09-15 22:01:04 发布