python 基本语句

print(''' 

hello word

''')

hello word 

print (" hello woerd")

hello

woed

print("hello \nword ")

hello word

print (r"hello word ")

hello work

a="dogs"

print ("hello %s" %a)

hello dogs

a=123

print("hello %d " %a)

heelo 123

a=123

print ("hello %i" %a)

hello 123

字符串格式化

a=123

printf (hello %d " %a)

hello 123

a=123

print("hello %i " %a)

hello 123 

a=123

print ("hello %s " %a)

hello 123

运算符

10%20

10

2**8

256

12>>2

3

12>>3

1

进制转换

二进制转换

a=123

b=bin(a)

print(b)

ob1111011

a=123

b=oct(a)

print (b)

0o173

a=123

b=hex(a)

print(b)

 ox7b

转换二进制

a='0b1111011'

b=int (a,base=2)

print (b)

123

a='ob1111011'

b=int(a,base=2)

c=oct(b)

print(c)

0o173

八进制转换

a='0o173'

b=int(a,base=8)

print(b)

123

a='0o173'

b=int(a ,base=8)

c=bin(b)

print(c)

ob1111011

a='0o173'

b=int (a,base=8)

c=hex(b)

print(c)

ox7b

a=123

a=b=c=456

print(a,b,c)

456 456 456

if 3>4

  print("牛逼")

else;

print ("不牛逼")

不牛逼

a=input(“请输入的数字”)

print(“输入的数字 %s " %a)

请输入的数字123

输入的数字123

求100内的奇数之和 偶数之和

odd=0 

oven=0 

for i in range (1,101):

if 1%2:

odd=odd+i

else:

oven=oven+i

print(odd)

print(oven)

二分法实现

a=input("请输入一个五位数:")

a=int (a)

if a > 99:

  if a > 9999:

  print("5位数")

 if a > 999

print("4位数")

else:

print("3位数")

else:

 print("2位数") if a > 9 else print ("1位数")

list range(1,20,2)

1,3,5,7,9,11,13,15,17,19

### continue,,执行continux之后,立刻执行本次循环后面的

for  i in range (5)

if i ==3

prinf(i)

0   1   2   4  5

###break,,执行了break之后表示跳出循环,循环终止

for i in range (10):

if i  == 4 :

break 

print(i)

0  1  2  3  4

原文地址:https://www.cnblogs.com/liu1026/p/7816706.html