
本文共 10472 字,大约阅读时间需要 34 分钟。
Python������
- ���������python������
- ������
- ������������
- ������������������
- ���������������
- ���������������
- ������������if...else...
- ������������-������
���������python������
������������
1.���notepad++������������������������������������������
print('HelloWorld')print('python���������������������������������������')
2.���������HelloWorld.py������������������.py������������������
3.������ cmd������������������python HelloWorld.py,������������������������������python������������������������������python������������������������������������������
python������������������������������������������������������
������
������������������
eat = 100+20+30cloth = 200+300print('total=',cloth+eat)
���������������������������������������������������������������������������������������������������������������������������������������������������������
������������������
������������
name = 'xiaoyafei'
������name���������������������/���������������'xiaoyafei'���������������������������
������������������
- ���������������������������������������������������������
- ������������������������������������������
- ���������������������������������������
['and','as','class']
������������
���������
AgeOfXiao = 20NumberOfStudents = 56
���������
age_of_Xiao = 20Number_of_Stundets = 56
������
������������������������������������������������python���������������������������������������������������������������������������������������������������������������
AGE_OF_XIAO = 22 #������������������
������������
������������������
name = input('what is your name?')print('Hello,'+name)
���������������������������������������������������������������name������������������������
���������������������������������������������������
name = input('what is your name?')age = input('what is your age?')hometown = input('what is your hometown?')print("hello",name,"your age:",age,"years old,you come from,",hometown)
���������������������������
what is your name?awhat is your age?bwhat is your hometown?chello a your age: b years old,you come from, c
������
������������������
- ������������������������������������������������������������������������������������������������������
- ���������������������������������������������������
������������
������������������������������������������������������������������������������������������������������������������������������������������python���������������������������������������3������������������������������������������
������
int(������)
���32���������������������������������32���������������������-2 ** 31~2 ** 31-1
���64���������������������������������64���������������������-2 ** 63~2 ** 63-1
long(���������)
���C���������������python���������������������������������������python������������������������������������������������������������������������������������������������������������
��������� ���python2.2���������������������������������python������������������������������������������������������������������������������������������L���������������������������
���python3���������������long���������������������������int
>>> a = 2**64>>> type(a)������������������class 'int' #���python3���������������
������int���long���������������float���������������������
���������
���python���������������������������������������������������
>>> name = "xiaoyafei" #���������>>> age = '22' #���������>>> age2 = 22>>> >>> msg = '''my name is xiaoyafei,i am 22 years old.''' #���������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
>>> msg = "my name is xiaoyafei,I'm 22 years old."
������������������������������������������������������������������������
>>> msg = '''... ������������������������... ������������������������... '''
���������������
>>> name = 'xiaoyafei'>>> age = '22'>>> name + age #���������������������������'xiaoyafei22'>>> name * 10 #���������������������������������'xiaoyafeixiaoyafeixiaoyafeixiaoyafeixiaoyafeixiaoyafeixiaoyafeixiaoyafeixiaoyafeixiaoyafei'
���������������������������������������������������������������������������������������������������������
>>> name = 'xiaoyafei'>>> age = 10>>> type(name)>>> type(age) >>> name + ageTraceback (most recent call last): File " ", line 1, in TypeError: must be str, not int #������������������������
���������
���������������������������������������������True���Flase
>>> a = 2>>> b = 5>>> a > b #���������������Flase���������False>>> a < b #������������True���������True
���������������
#-*- coding:utf-8 -*-name = input('Name:')age = input('Age:')addr = input('Addr:')info = '''--------------info of %s---------------Name :%s Age :%s Addr :%s '''%(name,name,age,addr)print(info)
%s������������������������������������������������������%d���������������
���������������������Name:xiaoyafeiAge:22Addr:HangZhou--------------info of xiaoyafei---------------Name :xiaoyafei Age :22 Addr :HangZhou
������������������������������������������%s���������������������������������������������������
>>> age = input('Age:') #input������������������������������������������������Age:22>>> type(age)
������������������������������������������������������[int(youStr)]
������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
������������
���������������������a=10,b=20
���������
������������
������������
������������
������������if...else...
���������
if ��������� ������������������������������
���������
xiaoyafei_age = 22if xiaoyafei_age<23: #������ print('he is young') #������������������������
���������������
he is young
���������
if ������: ������������������������������else: if������������������������������������
���������
xiaoyafei_age = 24if xiaoyafei_age<23: print('���������������')else: print('������������')
���������������������
������������
���������
if ������: ������������������������elif ������: ������������������������������������elif ������: ������������������������������������elif ������: ������������������������������������ else: ������������������������������������������
���������������������������������
# -*- coding:utf-8 -*-xiaoyafei_age = 22guess = int(input('>>:'))if guess >xiaoyafei_age: print('���������������������������')elif guess < xiaoyafei_age: print('���������������������������')else: print('���������������������')
������������������������������������ABCDE5������������������������������������������
A 90-100
B 80-89
C 60-79
D 40-59
E 0-39
������������������0-100���������������������������������������������������score = input('���������������')if score > 100: print('������������100')elif score >=90: print('A')elif score >=80: print('B')elif score >=70: print('C')elif socre >=60: print('D')else: print('E')
���������������������������������������95��������� ������������������������A,������95 ������������������������������elif score >=80:���, ������������������B������������������������������������������������������������������������������������������������������������������������������������
������������-������
while������
������
������������while���������������������while���������������������������������������������while���������������
���������������0������100������������������������������+1
count = 0while count <= 100: #������count<=100��������������������������������� print('loop:',count) count += 1
���������
loop: 0loop: 1loop: 2.....loop: 98loop: 99loop: 100
������������������������������1-100������������������������������
���������������������������������������������������������������������2���������������������������������������������������2���������������������������2���������������������������
count = 0while count<=100: #������count<=100������������������������������ if count %2 == 0: #��������� print('loop:'count) count += 1 #������������������������count+1,���������������������������������������count������������0
���������
������������������������������������������������������������������������������������������
while���������������������������������������������������������������������������������������������������������������
count = 0while True: #True��������������������� print('���������������������������������������������......',count) count +=1
������������������������������������������������������������������������������������������������������������������������������������������������[ctrl+c]
������
������������������
������������������������������������������������������������������������������������������������������������������break���continue������
- break���������������������������������������������������������������������������
- continue���break���������������������������continue������������������������������������������������������������break���������������������
break������
count = 0while count<=5: print('loop:',count) if count == 3: break count +=1print('out of while loop')
���������������������
loop: 0loop: 1loop: 2loop: 3out of while loop
coutinue������
count = 0while count<=10: count +=1 if count>3 and count<8: #������������������count>3������count<8������������������������������ continue print('loop:',count)print('game over')
���������������������
loop: 1loop: 2loop: 3loop: 8loop: 9loop: 10loop: 11game over
while...else...
���������������else������������if������������������python������������while...else������
while���������else������������������while���������������������������������������break���������������������������else���������������count = 0while count<=5: count +=1 print('loop:',count)else: print('���������������������...')print('out of while loop')
���������������������
loop: 1loop: 2loop: 3loop: 4loop: 5loop: 6���������������������...out of while loop
���������������������������break������������������������else������
count = 0while count <= 10: count +=1 print('loop:',count) if count ==2: breakelse: print('���������break������')print('out of while loop')
���������������������
loop: 1loop: 2out of while loop
发表评论
最新留言
关于作者
