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

Python learning Chapter 1 (basic grammar)

編輯:Python
dir(__builtins__) : You can print it out Python Using functions .
help(int) : You can print out the function description .
print("") : The console outputs strings or numbers .
if and else : There is no need to use parentheses for this judgment , Just separate the spaces in the middle , End with a colon (if tend > 10:) separate .
elif : Similar to other languages else if, stay Python It can be used inside elif Write it in such a simple way .
input("") : Output the string inside , And receive the console input data assignment .
and and or : Can be seen as && and ||
Type conversion : int()、str()、float() Convert to integers respectively 、 Strings and floating point numbers , If it cannot be converted, an exception will be thrown .
Get data type and judgment type : type(True)、isinstance(30.3,float) Return data types respectively , And judge the data type to return
true and false
matters needing attention : stay Python Inside , Variables can also be used in the same way as in other languages , The only difference is that you don't have to decide
Semantic type .
\ : Backslashes can be used as escape characters print('sdhjsd\'sdsjhdhj'), If you want to print a string, do not add \ An exception will be reported , because
He would end it in quotation marks
Output special characters : print(r"C:\now\"), This code does not add r He will automatically escape and wrap lines , To complete the output, you need to add r
Three quotation mark code practice , Spaces and line breaks will be automatically output , Adding a single quotation mark will report an exception :
print("""jsadnjsj,
snakjldlwk,
asdwdwjdjd,
djskeee""")
Here is a piece of code that can repeat the judgment , The requirements must be very familiar with :
number = input(" Please enter your ideal number :")
// Assign the console number to redis.
redis = int(number)
while redis != 20:
number = input(" Wrong input , Please re-enter :")
// The re entered data must also be assigned to redis.
redis = int(number)
print(" Congratulations on your success ")


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