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

Basic knowledge points of Python learning notes

編輯:Python

Catalog

Basic understanding

Basic type conversion function

print function

input function

if sentence

Thinking questions


Basic understanding

A program needs to run three cores of hardware :CPU, Memory , Hard disk .

CPU: Responsible for data processing and calculation .

Memory : Fast , Small space , There are many chips on the memory module , Memory modules usually have only 4G,8G,16G,32G.

Hard disk : Slow speed , The space is large , An important parameter when buying a hard disk is “ speed ”, The faster the speed, the faster the reading speed .

stay python There is no need to specify the type of variables defined in .

Data types can be divided into numeric and non numeric types .

Digital : integer , floating-point , Boolean type , Plural .

Non digital : character string , list , Tuples , Dictionaries .

Basic type conversion function

int(xx) function

effect : hold xx To integer .

str(xx)

effect : hold xx To string .

chr(xx)

effect : hold xx To a character .

More functions can be self Baidu .

print function

stay python Use this function in to print content .

input function

input Function when there is something in parentheses , It will prompt the user to enter relevant information as a prompt . It should be noted that ,input The return value of is a string , If the content needs to be ''445 '' When the string of is converted to an integer , You can use int() function .

hh = int(input(" Please enter age :"))
print(hh)
print(type(hh)) #type Determine the variable type 


if sentence

if age > 30: print(age) # if How to write sentences , After the condition is written, enter four spaces or one tab, But remember not to mix the two in a program .

Be careful ! Be careful ! Be careful ! Class III warning .

if Statement is a block of the adjacent indented code below .

  If the conditions are met , Three print Metropolitan output , If you don't want to output the last one, you can remove the indentation .

# Scissors, stone, and cloth
player = int(input(" Please enter scissors (1) stone (2) cloth (3)"))
comp = 3
if ((player == 1 and comp == 3)
or (player == 2 and comp == 1)
or (player == 3 and comp == 2)):
print(" Is too weak , Computer brother ")
elif (player == 1 and comp == 1) or (player == 2 and comp == 2) or (player == 3 and comp == 3):
print(" It's a draw ")
else:
print(" Ah ah , I am lost ")

Thinking questions

python It is extremely easy to read , So how to wrap a line if you encounter a particularly large line of code ?

example : Aforementioned if The statement encloses the judgment condition with two parentheses , Be careful not to run into colons . Then press or Line break , Keep... On each line 8 A space .


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