In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about how to review Python basics. Many people may not know much about it. In order to let you know more, Xiaobian summarized the following contents for you. I hope you can gain something according to this article.
I. Review content
1. Top
interpreter
Coding (2.7 default ascii, 3.6 default utf-8)
2、print("hello")2.7
print "hello" 3.6
3. Relationship between codes
ascii unicode (at least two bytes) gbk utf-8
1 byte Minimum 2 bytes 2 Chinese 3 bytes
4, named
Initials, not numbers.
Variable names cannot be keywords
Numeric letters underlined
The meaning of variable existence--> Convenient call
5. Conditions
If conditions:
pass
elif condition:
pass
else:
pass
Note the indentation, colon
6、while
while conditions:
pass Every time the condition is judged to be true, infinite execution
continue Abort this loop and restart the loop
break Terminates all loops
7. Operators
*=
+=
-=
/=
%= remainder
One equal sign is assigned, two equal signs are equal.
num = 13
zq = num % 2 #remainder
if zq == 0:
#Even numbers
else:
#Odd
in Determine if the element is not in the list
num = "zq"
li = ["zq","zw"]
if num in li:
print('zai')
else:
print('buzai')
Add another one to determine whether it starts with z
if num in li and num.startwith('z')
# and can add a condition
8. Basic data types
int, plastic
n = 123
n = int(123) # int class--init--
s = "123"
m = int(s) #String type conversion integer
There's a length limit to shaping, 32-bit computers plus or minus 2 to the 31st power...(python2.7)
In Python 3.6, there is no longer a long, no matter how long the number is. 2.7 The inside exceeds the range and converts to long shaping
s = "132sdfg" #String contains only digits
m = int(s)
str, string
s = "zq"
s = str("zq")
a = 123
m = str(a) converts a number to a string
=======
bytes => byte type
str => String
Purpose: byte to string conversion
b = objects of byte type
# m = bytes(b)
m = str(b,encoding="utf-8")
Start letter capitalization Go space Change case replacement Is it a number, letter beginning and end Search
Number Format Coding Decoding Center Left Floating Right Floating Connection
li = ["zq","ss"]
l1 = "_".join(li)
l1 corresponds to zq_ss
list, list
i = [11,22,33]
i = list(11,22,33) This is wrong
i = list([11,22,33]) list is a class name followed by parentheses. There can only be one element inside, but it must be enclosed in brackets and sequence.
=====
t = (11,22,33)
i = list([t]) This is wrong and the result is [(11,22,33)]
i = list(t) This is correct
t = [11,22,33]
t = [11, 22, 33,] These two are similar.
Common functions of lists:
index
slice
for
length
enumerate
Delete del li[0]
del li[0:2]
Unique functions:
flip
sort
additional
inserted
index position
delete
pop
extended
clear
tuple:
t = (11,22,33,44)
t = tuple(iterable object)
li = (11,22,33,44)
l1 = tuple(li)
Public functions:
index
slice
for
length
enumerate
in
Unique functions:
number
index position
Feature: Cannot modify...
dict:
d = {"k":123,"k2":65}
d2 = {
"k":123,
"k2":156
}
li = [1,2,3,4]
Dictionary: key: 10 increments
value: element of the list
dic = []
for i,j in enumerate(li,10):
new_dict = dict(enumerate(li,10))
Public functions:
index
Add dic[key]=vlue
delete
for
length
in
Unique functions:
Get Haskey--> is
update
fromkey
String, byte
str
bytes
a = bytes encoded by "zhang qiang" gbk
b = bytes(a,encoding="gbk") type(b)=> bytes
c = str(b,encoding="gbk")
int optimization mechanism
a = 123
b = 123
id(a)
Same, because there are optimizations,-5 to 257
a = 123
b = a
After reading the above, do you have any further understanding of how to do python fundamentals review? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.
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.