Mandatory conversion type
1 age = int(input("age:"))
打印出数据类型
1 print(type(age))
#raw_input 2.x input 3.x
输入的数据类型默认为string
1 转义符\:print 'It\ 's a dog' 2 输出:It's a dog 3 自然字符串:在字符串前加上r,字符串即使有转义符,也能原样保留 4 print r"hello boy\nhello boy" 5 输出:hello boy\nhello boy
1 字符串的重复:"hello"*20
子字符串
1 #索引运算符从0开始索引 2 #切片运算符[a:b]是指从第a下标开始到第b-1下标。第一位下标为0 3 c1="abcdefg" 4 c2=c1[0] 5 c3=c1[7] 6 c4=c1[:2] 7 c5=c1[2:] 8 c6=c1[4:7] 9 print (c1,c2,c3,c4,c5,c6)
列表的符号是[]
元组的符号是()
元组不能修改
集合的格式是: set(元素)
1 if xx == xx : 2 print() 3 elif xx > xx: 4 print() 5 else: 6 print() 7 8 while True: 9 print() 10 11 for i in range(10): #i是临时变量;range(0,10,2)在0-10的范围内隔两个输出一次 12 print("loop ",i)
三元运算
1 result = 值1 if 条件 else 值2
如果条件为真:result = 值1
如果条件为假:result = 值2
continue功能是跳出本次循环,继续下次循环
break功能是结束整个循环