目录
python也是由C语言发展而来
python模仿的shell
1.注释三引号
# 多行注释"""内容"""\'''内容''' 在python中单引号和双引号的作用相同,但只能单引号或双引号各自成对出现。 # 单行注释#本行内容
2.python中输出函数是print
print("hello world") print('hello')
3.python中不用声明变量,即拿即用
a = 10.1 print(a)
4.标识符(程序员自定义的符号)
# <1> 由数字,字母,下划线组成,并且数字不能开头 # <2> 不能和关键字重合 # <3> 见名知意 # <4> 驼峰命名法 # 大驼峰:每一个单词的首字母大写. 类名 # 小驼峰:第一个单词首字母小写其他的大写. # windows编程中 函数名, 变量名 # <5>.通过下划线链接 # Linux编程当中. 统一使用下划线链接
5.查看python中的关键字
print(help("keywords"))
6.运算符(与C语言中的不同点)
b = 10 c = 3 # 除法 print(b/c) # 整除 print(b//c) # 幂运算 print(b**c) # 两个变量的数交换的三种实现方式:三杯水交换,两个数的和,异或 # 逻辑运算符 # and : 与运算符: 两个真且为真 # or : 或运算符: 有真就为真 # not : 非运算符: 真假互换
7.python的格式化输出(%s字符串,%d数字)
name = "蜡笔小新" age = 10 print("name=%s,age is %d" % (name,age)) print("name is ", name) print("age is ", age) # 取消使用多个print的换行操作(end="内容") print("name is ", name, end=" ") print("age is ", age)
8.python中的输入input
password = input("please input >>") print(password) # 查看类型并输出 print(type(password))
9.强制类型转换
print(type(int(password))) # 将字符串转换成int类型