程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Notes dapprentissage Python

編輯:Python

day1

#Opérations de fichiers
fp = open('D:/text.txt','a+')
print('hello word',file = fp)
fp.close()
#La variable a trois attributs
name = 'Xiao benjie'
print('Mémoire',id(name))
print('Type',type(name))
print('Valeur',name)
#Variable string connection
name = 'Li - si.'
age = 378
print('Mon nom est...' +name+ 'Cette année' +str(age)+ 'Année')
#Demande d'entrée(La variable par défaut est le type de chaîne)
input()La valeur de retour eststrType
a = int(input('Veuillez saisir le premier plus'))
b = int(input('Veuillez saisir le deuxième plus'))
print(a+b)
#Opérations de division
print(11//2) #//Opérateur de division entier Produits5
#Opération de puissance
print(2**3) #Représentation2Cubic
#Affectation en chaîne
a=b=c=20
#Affectation de déballage
a,b,c=20,30,40
#Échanger deux valeurs variables
a,b=20,30
a,b = b,a
print(a,b) //Produits30,20
#Comparer les opérateurs(Identification,Type,Valeur)
>,<,>=,<=,!=,==C'est vrai.vaueComparaison
is, is not C'est vrai.idComparaison
Le résultat retourné est un type booléen
a,b=20,30
print('a>bC'est ça?',a>b) //Produitsfalse
#Opérateurs logiques
a,b=1,2
s='hello word'
print(a==1 and b==2)
print(a==1 or b==3)
print(not a) //false
print('w' in s) //true
print('w' not in s) //false
#Opérations de bits
& | << >>

#Structure des branches
money=int(input('Saisissez un entier'))
if money<100:
print('Montant inférieur à100')
if money%2!=0:
print(' Le montant est impair ')
else:
print(' Le montant est pair ')
elif money>100 and money<200:
print('Montant supérieur à100Moins de200')
else:
print('Montant supérieur à200')

day2

#Expression conditionnelle
'''
Syntaxe:
x if Conditions de jugement else y
Règles de fonctionnement:La condition de jugement esttrue La valeur de retour estx,La condition de jugement estfalse La valeur de retour esty
'''
num_a = int(input('EntréeaValeur de'))
num_b = int(input('EntréebValeur de'))
print(str(num_a)+'Plus grand que'+str(num_b) if num_a>num_b else str(num_a)+'Inférieur ou égal à'+str(num_b))
#passDéclarations
Ne fais rien.,Juste un substituant,Utilisez là où vous devez écrire une déclaration
answer = input('Êtes - vous membre?')
if answer == 'y':
pass
else:
pass
#range()
r=range(10) #[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],Par défaut à partir de0C'est parti.,Différence par défaut1 Devenir un pas
print(r) #Produits range(0,10) La valeur de retour est un Itérateur
print(list(r)) #Pour voirrangeSéquence d'entiers dans l'objet Produits[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
r=range(1,10) #[1, 2, 3, 4, 5, 6, 7, 8, 9],De1C'est parti.,10Fin,L'étape par défaut est1
r=range(1,10,2) #[1, 3, 5, 7, 9], De1Ça commence à10Fin,Par étapes2
print(10 in r) #false Jugement10Oui NonrDans la séquence
print(10 not in r) #true
#Cycle
#whileCycle
while Conditions:
Corps circulatoire
#forCycle
for item in 'Python':
print(item) //ProduitsP y t h o n
for item in range(10):
print(item) //Produits0,1,2,3,4,5,6,7,8,9
for _ in range(5): //Répétition du cycle5Oui.
print('La vie est courte.,Je l'utilise.Python')
#else Cycle de collocation
Une fois le cycle terminé normalement (Je n'ai pas rencontrébreak),Sera exécutéelseDéclarations
for:
else:
while:
else:

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved