In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the language element and branch loop structure of python grammar". In the daily operation, I believe that many people have doubts about what is the language element and branch loop structure of python grammar. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what is the language element and branch loop structure of python grammar". Next, please follow the editor to study!
1. Language element 1. Variables and their types
(1) variable
A variable is a quantity that can be changed.
Using variables for the first time divides space in memory and initializes values
Once again, use the variable to no longer divide the space and modify the original space.
(2) variable type
① numeric type
Int floatbool:True 、 False
② string type
String operator: + * in not in slice: syntax: [start: end: step] subscript / index: subscript in python starts at 0
Sample code:
A = 10 # integer b = 3.1 # floating point c = "lhsmdqwer" # string type print (type (a), type (b) Type (c))''l h s m d q w e r0 1 2 3 4 5 6 7 8-9-8-7-6-5-4-3-2-1'''print (c [2: 9:2]) # sdwrprint (c [- 1 sdwrprint-(len (c) + 1):-1]) # reverse output
Running result:
two。 Variable naming convention: ① can only consist of numbers, letters, _ (underscore) ② cannot start with a number ③ cannot be a keyword ④ case-sensitive naming convention: underscore segmentation: variable name user_name, first_name Card_id great hump nomenclature: UserName, FirstName, CardId3. The use of variables
When a variable is declared, it must be initialized to tell the computer how much memory to allocate to the variable.
The variable also has its scope, and I'm going to talk about it later on, which is not appropriate here.
4. Operator comparison operator: =
< >= logical operator: and or not ternary operator: an if a > b else b # choose an if a > b otherwise select b
Code example:
NameA = 1nameB = 2nameC = "lhsmdjjjhhhqwer" nameD = "OKOK" print (nameA = = nameB) # Falseprint ('jjj' not in nameC) print (' jjj' in nameC) print (nameA * nameB) print (nameC + nameD) print (nameB * nameD)
Running result:
Second, branch loop structure 1.if ① if ② if...else... ③ if...elif...else...2.for. In
See sample code
3.while
See sample code
Notice the difference between break and continue
Sample code:
NameA = 1nameB = 2nameC = "lhsmdjjjhhhqwer" nameD = "OKOK" for i in nameC: print (I) if nameA = = nameB: print ('nameA = = nameB') elif nameA! = nameB: print (' nameA! = nameB') else: print ('error') print ('-split line 1Mutel') num = 0while (num < len (nameC): print (nameC [num]) num + = 1 if num = = 3: breakprint ('- split line 2muri') num = 0while (num < len (nameC)): print (nameC [num]) num + = 1 if num = = 3: continue so far The study on "what is the language element and branch loop structure of python grammar" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.