Home Backend Development Python Tutorial What are the must-memorize contents for Python?

What are the must-memorize contents for Python?

Oct 21, 2020 pm 02:27 PM

Python must memorize content: 1. Variables, master the naming method of variables; 2. Data types, master the mutual conversion of int, float, bool and other types; 3. Master arrays Type, defined in [[ ]], with commas separating the elements.

What are the must-memorize contents for Python?

Python must memorize content:

1. Variables

1. Variable

•refers to a variable amount during program execution;

•defining a variable will be accompanied by three characteristics, namely memory ID, data type and variable value.

•Before running other languages, you must manually release the memory space of the program. However, the python interpreter has its own memory recycling mechanism. Once the python program finishes running, the memory space will be automatically released.

age=10

print(id(age),type(age),age)

2. Constant

•Refers to the process of program execution , immutable quantity;

•Generally, capital letters are used to define constants.

AGE=10

print(AGE)

3. Naming method of variables

•Camel case

AgeOfOldboy=72

•Underscore

age_of_oldboy=72

2. Interacting with the program

In ancient times, when we went to the bank to withdraw money, we needed A bank clerk waited for us to enter our account and password to him, and then he went to verify it. After success, we entered and told him the withdrawal amount.

Proud modern people will provide customers with an ATM machine (that is, a computer), allowing the ATM machine to interact with the user, thus replacing manpower. However, the machine is dead, and we must write programs for it to run. This requires our programming language to have a mechanism that can interact with the user and receive user input data.

1, python3

•Python3 supports UTF-8 Chinese encoding by default. python2 needs to add # -*- coding:utf-8 -*- at the head of the code.

•Input in python3, no matter what type of value is entered, it will be saved as str (string) type

name=input('please enter the username: ')

print(id(name),type(name),name)

2, python2

•raw_input in python2 is the same as input in python3;

name=raw_input( 'please enter the username: ')

print(id(name),type(name),name)

•Input in python2, you must enter a value. What type this value is will What type is saved.

name=input('please enter the username: ')

print(id(name),type(name),name)

3. Data Type

1, int integer type

•Generally used to define age, ID number, QQ number, level, etc.

age=18

id=130530198805240011

qq=379048558

level=99

2, float floating point type

•Generally used to define height, weight, Salary, etc.

height=1.81

height=float(1.81)

3, str string type

•Generally used to define a person’s name, Gender, status, etc.;

• Generally, strings are placed in single quotes, double quotes, or triple quotes.

name='egon'

sex='female'

age=18

•String splicing uses " "

name='egon'

sex='female'

age=18

print(name sex str(age))

Note: here The age variable value is 18, which is an int type and cannot be concatenated with strings. You need to use str(age) to convert it to a string type.

•Use "*" for string splicing

name='egon'

print(name*10)

4, bool Boolean value type

•There are only two values: True and False;

•Mostly used for judgment.

age=73

AGE=18

print(age < AGE)

print(age > AGE)

5. Conversion between various types

•Integer type——>Floating point type

a=18

print(float(a))

•Floating point type——>Integer type

a=1.81

print(int(a))

•Floating point type——>String type

a=1.81

print(str(a))

•Integer type——>String type

a=18

print(str(a))

4. Array type

1. List[]

•List in python, defined in [], use "comma" to separate the elements;

info=['egon','alex',18]

print(info[2])

•Elements can be any data type or array type;

•Character elements need to be enclosed in quotation marks, integers, floating point types, lists, etc. do not need quotation marks.

info=[13,18.1,'alex',['egon','tony']]

print(info[3][0])

2 , Dictionary {}

•Dictionary in Python, also called associative array, is defined in {}, and the elements inside are expressed in the project name: project content format, and the elements are separated by "comma";

info={'name':'egon','sex':'male',3:18}

print(info[3])

•Project content can It is any data type or array type;

•The string type in the project content needs to be enclosed in quotes, while integers, floating point types, lists, etc. do not need quotes.

info={'Name':'Aigen','Gender':'Male','Muscle':['Yes','No']}

print(info[ 'Muscle'][1])

info={'Name':'Aigen','Gender':'Male','Muscle':123}

print(info['Muscle'])

info={'Name':'Aigen','Gender':'Male','Muscle':18.1}

print(info['Muscle'])

info={'Name':'Aigen','Gender':'Male','Muscle':'None'}

print(info['Muscle' ][1])

5. Formatted output

•my name is xxx, my age is xxx

•Need to use placeholders %s

name=input('user_name>>: ')

age=input('user_age>>: ')

print('my name is %s, my age is %s' %(name,age))

6. Operator

1. Arithmetic operator

• - * /

print(5 5) #5 plus 5 equals 10

print(5-5) #5 minus 5 equals 0

print(5*5) #5 times 5 is equal to 25

print(5/2) #5 divided by 2 is equal to 2.5

•Find the integer part of the quotient // Find the remainder part of the quotient % power**

print(5//2) #The quotient of 5 divided by 2 is equal to 2 with a remainder of 1, only take the quotient 2

print(5%2) #The quotient of 5 divided by 2 is equal to 2 with a remainder of 1, only take the remainder 1

print(3**2) #2 raised to the power of 3 is 3 times 3 equal to 9

2, comparison operator

•> < > = <= == !=

print(30 > 20)

print(30 < 20)

print(30 >= 30)

print(30 <= 30)

print(30 == 30)

print(30 != 40)

3. Logical operator

•Logical AND and Logical OR or Logical NOT Bitwise AND & Bitwise OR|

•Logical AND and, all conditions must be met for the result to be True;

• Logical or or, as long as one condition is met, the result will be True;

• Logical not, the result will be inverted.

name='egon'

age=18

print(age > 15 and name == 'egon')

print(age > ; 15 or name != 'egon')

print(not age > 15)

For a large number of free learning recommendations, please visit python tutorial(video)

The above is the detailed content of What are the must-memorize contents for Python?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

What are regular expressions? What are regular expressions? Mar 20, 2025 pm 06:25 PM

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

How to dynamically create an object through a string and call its methods in Python? How to dynamically create an object through a string and call its methods in Python? Apr 01, 2025 pm 11:18 PM

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

What are some popular Python libraries and their uses? What are some popular Python libraries and their uses? Mar 21, 2025 pm 06:46 PM

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

See all articles