example: [1,2,3,4]4. TuplesA set of data enclosed in parentheses, for example: (404, ' Page not found ')5. DictionariesThe key-value pair that the curly brace expands, for example: {name: ' Tom ', age:20}6. ObjectsExamples of classes, functions, and so on.These data types will be covered in detail later, so here's a quick look.Definition and assignment of variablesDefining variables in Python is not the sa
1. ScopeIn python, the scope is divided into four situations: L: local, local scope, that is, the variables defined in the function;E: enclosing: The local scope of nested parent functions, that is, the local scope of the upper-level functions that contain this function, but not global;G: globa, global variable, which is defined at the module level; B: built-in, variable in the system fixed module, such as
This article mainly introduces the variables in Python and Their Naming and printing. It is the basic knowledge in getting started with Python. If you need them, you can refer to the variable in the program as a name, this makes it easier for us to remember.
cars = 100 space_in_a_car = 4.0 drivers = 30 passengers = 90 cars_not_driven = cars - drivers cars_driv
Configure the python environment variable in Windows
Configure python environment variables in Windows(23:40:14)Reprinted
Tags:Miscellaneous
By default, after python is installed in windows, the system does not automatically add corresponding environment
One, variable
Variable definition: Variables is used to store infomation to referrenced and manipulated in a computer program.
Intermediate operation results for stored program runs
Identity
Store
Variables are represented by a variable name in the program
The variable name must be a combination of case English, numeric, and _, and cannot start with a number
Sensitive to case
Recom
development of the default is the ASCII code, ASCII code does not contain Chinese, so Python2 tells the Python interpreter to utf-8 encoding way to execute the file.There's no use in Python3, Python3 already supports Chinese encodingWrite a login Validator 1Usernme = input ("Please enter user name:")2Password = input ("Please enter your password:")3 4 ifUsernme = ="Root" andPassword = ="123123":5 Print
threads within a process makes it easy to share data among multiple threadsThe downside is that a thread is arbitrarily modifying a global variable that can cause confusion among multiple threads about global variables (that is, thread non-security)==================================================================Note: The above course notes for the study of the
notation reserved 2 decimal places>> 1.29e+00Formatting operator Auxiliary directivesSymbolic effect* Define width or decimal point accuracy-Used for left alignment+ Show plus sign (+) in front of positive number# 0 (' 0 ') is displayed in front of the octal number, preceded by ' 0x ' or ' 0X ' in hexadecimal (depending onUsing ' x ' or ' x ')0 The number shown is preceded by ' 0 ' instead of the default space% ' percent ' output a single '% '(VAR) mapping variable (dictionary parameter)M.N m i
OK in (' Y ', ' ye ', ' yes ': return True
if OK in (' n ', ' No ', ' nop ', ' Nope '): return False
retries = retries-1
if Retrie s
When you call the above function, you can modify the number of retries and the output of the prompt language, if you are more lazy, then nothing to change.
Second, Python uses the function default value to realize function static variable function
Static variable
Python advanced tutorial: multiple transfer methods of function parameters, python advanced tutorial
We have been touched by the function parameter (arguments) transfer. At that time, we passed the corresponding parameters based on the location. We will be exposed to more parameter passing methods.
Recall location transfer:Copy codeThe Code is as follows:Def f (a
By default, after python is installed in windows, the system does not automatically add corresponding environment variables. In this case, you cannot directly use Python commands in the command line.
1. first, you must register the python environment variable in the system. Assume that the
can use the ' + ' sign to stitch the string
List (lists) uses [] to represent
The list list is the most frequently used data type in Python, and lists can accomplish the data structure implementation of most collection classes. Lists support characters, numbers, and even nesting
#!/usr/bin/python #-*-Coding:utf-8-*- list = [ "runoob 7862.23john70.2 ] tinylist = [123 ' john "]
Python comments, python comments multiple lines
Annotations are used to describe the functions of the Code, the algorithms used, the code writers, and the creation and modification time.
Annotations are part of the code and play a complementary role in code description.Python Annotation
A single-line comment in Python
What is a variable?Example:>>> message = "hello,python!" >>> print (message) hello,python!The message here is the variable. You can modify the value of a variable at any time in your program, and Python will always record the latest value of the variable.what are the rules for variable commands?
make up elements (containing a tuple of all the parent classes)"""classpub (): _name='variables of type protected' __info='variables of private type' def_func (self):Print("This is a protected type of method") def __FUNC2(self):Print('This is a private type of method') defGet (self):return(self.)__info) A=
Using static variables in python classes and functions
This example describes how to use static variables in python classes and functions. Share it with you for your reference. The specific analysis is as follows:
It seems impossible to use static variables in
cannot be changed.Character encoding:The commonly seen #-*-Coding:utf-8-*-represents the encoding of the utf-8 used. It supports 1 bytes of English and accounts for 3 bytes of Chinese. Chinese is supported by default in Python3, but not supported in python2, this procedure needs to be written.Comments:Single-line Comment: #, multiline Comment: "", which can also be used to print multiple lines of character
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.