Defined three methods
#The first
var1=12
The second #
var2=var3=13
# Third
var4,var5=("第一","第二")
# Variable type
'' '
- Digital Number The
2 strings char
. 3 list List
. 4 tuples tuple
. 5 Dictionary dict
. 6 set SET
the Python numbers do not limit the size of the
'' '
'' '
1. integer
no fractional part
comprising a positive number, plural, 0
Binary 0 only
in the beginning are 0b
0b110 = 6
beginning octal 0o
0o666 = 438
hex Ox
0xFFFF = 65535
' ''
a1=0b111
print(a1)
a2=0o666
print(a2)
a3=0xffff
print(a3)
'' '
2 float
is decimal
common formats
3.1415926
3. A = 3.0
.4 = 0.4
' ''
'' '
3 scientific notation
314.15 = 3.1415e2
3.15125e3 = 315.125
' ''
a6=3.15125e3
print(a6)
" '
4. The complex
features in python
mathematical same: as the real and imaginary portions
. 5 3j +
3j
' ''
a=4j
print(a)
Print. 4J
'' '
Boolean: true or false value used to represent the
only two values: True, False (case sensitive)
in Python be used when the digital True = 1, False = 0
may be used when the digital
' ''
age1=21+True
print(age1)
age2=21+False
print(age2)
#打印22 和 21
'' '
String
often can not be represented by digital
information in textual
form quotes the content of
1. single quotes
2. double quotation
3. three marks: multi-line information indicates
single or double quotation marks meaning that is consistent
---- Description : single or double quotation marks can only be a single line, multi-line triple quotes
' ''
love="我爱学习"
print(love)
#打印出:我爱学习
love2="""
我爱
学习
学习让我
快乐,
学习让我头秃
"""
print(love2)
'''打印出
我爱
学习
学习让我
快乐,
学习让我头秃'''
#None represents nothing, commonly used placeholder,
# such as an empty, return0, almost
'' '
Today's example
1. Write 10 <cost <50 equivalent expression
2. int () converts the decimal integer, the result rounded up or rounded down
3. Write is determined whether a program is a leap year
'' '
# 1 example
cost=40
if (cost>10)and(cost<50):
print("True")
if 10<cost<50:
print("True")
Example # 2 (4 = 3.4 rounded up, rounded down. 3 =)
Print (int (3.4))
# result is rounded down
Example # 3
year=input("请输入年份")
if year.isdigit():
year=int(year)
if year%4==0:
'''
注意如果没有str(year),那么将会报错
TypeError: unsupported operand type(s) for +: 'int' and 'str'
'''
print(str(year)+"是闰年")
else:print(str(year)+"不是闰年")
else:
print("叫你输入的是年份")