x = 3
print(type(x)) # Prints "<type 'int'>"
print(x) # Prints "3"
print(x + 1 ) # Addition; prints "4"
print(x - 1) # Subtraction; prints "2"
print(x * 2 ) # Multiplication; prints "6"
print(x ** 2) # Exponentiation; prints "9"
x += 1
print(x) # Prints "4"
x *= 2
print(x) # Prints "8"
y = 2.5
print(type(y) )
print(y, y + 1, y * 2, y ** 2 )
t = True
f = False
print (type(t)) # Prints "<type 'bool'>"
print( t and f)# Logical AND; prints "False"
print (t or f ) # Logical OR; prints "True"
print (not t) # Logical NOT; prints "False"
print (t != f ) # Logical XOR; prints "True"
s = "hello"
print (s.capitalize() ) # Capitalize a string; prints "Hello"
print (s.upper() ) # Convert a string to uppercase; prints "HELLO"
print (s.rjust(7) ) # Right-justify a string, padding with spaces; prints " hello"
print (s.center(7) ) # Center a string, padding with spaces; prints " hello "
print( s.replace('l', '(ell)') ) # Replace all instances of one substring with another;
# prints "he(ell)(ell)o"
print (' world '.strip() ) # Strip leading and trailing whitespace; prints "world"
Python基本数据操作(1)字符/数字
最新推荐文章于 2024-10-24 19:24:37 发布
9273

被折叠的 条评论
为什么被折叠?



