This article mainly introduces the relevant information that summarizes the necessary knowledge for learning Python. Friends who need it can refer to it
1. Variables
1. Variables
•refers to the variables during program execution. , a variable quantity;
• 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 an immutable quantity during program execution ;
•Constants are generally defined in uppercase letters.
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 waiting for us to enter our account and password to him. , and then he goes to verify it and after it is successful, we enter the withdrawal amount and tell him.
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, a value must be entered, and the value will be saved as what type it is.
name=input('please enter the username: ') print(id(name),type(name),name)
3. Data type
1.int integer
•Generally used to define age, ID number, QQ number, grade, 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.;
•General 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: The age variable value here is 18, which is an integer and cannot be used as a character. For string concatenation, str(age) needs to be used to convert to string type.
•Use "*" for string splicing
name='egon' print(name*10)
4.bool Boolean value type
•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 is defined in [], and the elements are separated by "comma";
info=['egon','alex',18] print(info[2])
•Elements can be any data type or array type;
•Character elements need to be enclosed in quotes, integers, floating point types, lists, etc. do not need quotes.
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 "comma" is used between elements "separated;
info={'name':'egon','sex':'male',3:18} print(info[3])
•The project content can be any data type, any array type;
•The string type in the project content needs to be enclosed in quotes, integer, floating point, Lists, etc. do not require quotes.
info={'姓名':'爱根','性别':'男','肌肉':['有','无']} print(info['肌肉'][1]) info={'姓名':'爱根','性别':'男','肌肉':123} print(info['肌肉']) info={'姓名':'爱根','性别':'男','肌肉':18.1} print(info['肌肉']) info={'姓名':'爱根','性别':'男','肌肉':'无'} print(info['肌肉'][1])
5. Formatted output
•my name is xxx, my age is xxx
•You need to use the placeholder %s
name=input('user_name>>: ') age=input('user_age>>: ') print('my name is %s, my age is %s' %(name,age))
6. Operators
1. Arithmetic operators
• - * /
print(5+5) #5加5等于10 print(5-5) #5减5等于0 print(5*5) #5乘5等于25 print(5/2) #5除以2等于2.5
• Find the integer part of the quotient // Find the remainder part of the quotient % power **
print(5//2) #5除以2商等于2余1,只取商2 print(5%2) #5除以2商等于2余1,只取余数1 print(3**2) #3的2次幂是3乘3等于9
2. Comparison operators
• > •Logical AND, all conditions must be met before the result is True;
•Logical NOT, the result is negated.
print(30 > 20) print(30 < 20) print(30 >= 30) print(30 <= 30) print(30 == 30) print(30 != 40)
The above is the detailed content of Summary of essential knowledge for learning Python. For more information, please follow other related articles on the PHP Chinese website!

Python and C each have their own advantages, and the choice should be based on project requirements. 1) Python is suitable for rapid development and data processing due to its concise syntax and dynamic typing. 2)C is suitable for high performance and system programming due to its static typing and manual memory management.

Choosing Python or C depends on project requirements: 1) If you need rapid development, data processing and prototype design, choose Python; 2) If you need high performance, low latency and close hardware control, choose C.

By investing 2 hours of Python learning every day, you can effectively improve your programming skills. 1. Learn new knowledge: read documents or watch tutorials. 2. Practice: Write code and complete exercises. 3. Review: Consolidate the content you have learned. 4. Project practice: Apply what you have learned in actual projects. Such a structured learning plan can help you systematically master Python and achieve career goals.

Methods to learn Python efficiently within two hours include: 1. Review the basic knowledge and ensure that you are familiar with Python installation and basic syntax; 2. Understand the core concepts of Python, such as variables, lists, functions, etc.; 3. Master basic and advanced usage by using examples; 4. Learn common errors and debugging techniques; 5. Apply performance optimization and best practices, such as using list comprehensions and following the PEP8 style guide.

Python is suitable for beginners and data science, and C is suitable for system programming and game development. 1. Python is simple and easy to use, suitable for data science and web development. 2.C provides high performance and control, suitable for game development and system programming. The choice should be based on project needs and personal interests.

Python is more suitable for data science and rapid development, while C is more suitable for high performance and system programming. 1. Python syntax is concise and easy to learn, suitable for data processing and scientific computing. 2.C has complex syntax but excellent performance and is often used in game development and system programming.

It is feasible to invest two hours a day to learn Python. 1. Learn new knowledge: Learn new concepts in one hour, such as lists and dictionaries. 2. Practice and exercises: Use one hour to perform programming exercises, such as writing small programs. Through reasonable planning and perseverance, you can master the core concepts of Python in a short time.

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1
Easy-to-use and free code editor