In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail the basic knowledge about python. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
I. operator
In
"hello" in "asdfashellosdfadfadfa"
"li" in ['li','ok']
II. Basic data types
Int
A. Creation method
N1 = 123 # based on the int class, an object is created
N2 = int123 # created an object based on the int class
The unique features are:
Int class
Function 1
Function 1
Function 1
...
_ _ init__ initialization
B. Int internal optimization
N1 = 123
N2 = N1
N1 = 123
N2 = 123
= two copies of memory =
-5000257 this can be changed by modifying the source code, evolved from the c language, look up the source code
N1 = 123
N2 = 123
N1 = 123
N2 = 123
= = "memory address of the object = id (object or variable name of the object) so that you can view the memory address
C, length limit
With int, it is out of range (defined according to the computer)
32-bit operating system-2x 31-2m 31-1
64-bit operating system-2, 3, 3, 6, 3, 3, 6, 3, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 2, 6, 6, 6, 2, 6, 6, 6, 2, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 6, 4, 6, 6, 6, 6, 6, 6, 6, 4, 6, 4, 6, 4, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 4, 6, 4, 6, 6,
Long
Bytes: you can convert characters to bytes
Str
A. Creation method
S1 = "zq"
S1 = str ("zq")
B, unique functions
# remove spaces at both ends
# s1.strip ()
# to. The beginning
# s1.startwith ()
# finding subsequence
# s1.find ()
# replace a subsequence in a string with the specified value
# s1.replace ()
# change uppercase
# s1.upper ()
# Yes. Is it?
# s1.isalpha ()
C. Public function
Index: only one element can be fetched
Slices: taking multiple elements
Len:
For:
Coding, for:
Name = "Li Lu"
For i in name:
Print (I)
Bytes_list = bytes (I, encoding='utf-8')
Print (bytes_list)
For b in bytes_list:
# bytes default to hexadecimal
# output default hexadecimal per byte
Print (bbin (b))
1. When the for loop is in version 3.6, each element of the loop is a "character"
2. Character = "byte
Bytes_list = bytes ("string", encoding='utf-8')
# utf-8-"3 bytes
# gbk-"2 bytes
Print (bytes_list) # defaults to hexadecimal for every byte
For b in bytes_list:
Print (b) # defaults to decimal for each byte
The number in base 3 and 10 = "base 2"
Len
Id
Bin (decimal number)
Conversion of d, bytes and str
A = "Zhang Qiang"
# convert strings to bytes
B1 = bytes (a, encoding='utf-8')
Print (b1)
B2 = bytes (a _
Print (b2)
# convert bytes to strings
Print (str (b1 recording encodingbirds utfmur8')
Print (str (b2)
#
X = str ()
# create a string
# convert to string
O = bytes ()
# create bytes
# convert to bytes, strings, what encoding type of bytes to program
Str ()
Str class _ _ init__
List
A, create and transform
1. Create
A "collection" of variable elements, a list
Li = [11, 22, 33, 44]
Li = list ()
-
Str-> create strings, or convert others to strings
List-> create lists and convert other elements into lists
Li = ([11, 22, 33, 44])
2. Conversion
# iterable iterable: for can be cycled
A1 = "Zhang Qiang"
# for, character = > iterable
Li = list (A1) # for loop, which treats each element of the loop as an element of the list
Print (li)
# Dictionary #
Dic = {"K1": "zq", "K2": "sdfsdf"} # Note are curly braces
L3 = list (dic)
Print (L3)
L4 = list (dic.values ())
Print (L4)
L5 = list (dic.items ())
Print (L5)
# string, tuple, dictionary = "list
B, list-specific features
Li = [11, 22, 22, 3]
# append
# li.append ()
# clear
# li.clear ()
# extend yourself to yourself with another iterable object
# str string, list list, dictionary dic, tuple tuple
# z = "Zhang Qiang"
# li.extend (z)
# print (li)
# Flip, flip your own internal elements
# li.reverse ()
# insert the specified element into the specified location
# li.insert (1)
# print (li)
C. Public function
Li = ["zq", "fd", "gg", "rg"]
Index: only one element can be fetched
Slices: taking multiple elements
Li = ["sdf", "sdfe", "hdf", "sdgx"]
Print (li [1])
Print (li [1:3])
Sdfe # Index
['sdfe',' hdf'] # what type of slice is originally, what type of slice is taken out
For
Len
D, multi-layer nesting
Li = ['sdf','dff','we','gr']
Li = ["zq", 12, {"K1": "b1", "b2": {"qq": (11pime 22phi33), "ii": 741}}]
Li [2]-- > {"K1": "b1", "b2": {"qq": (11, 22), "ii": 741}}
Li [2] ['k2'] = > {"qq": (11 Magne22, 33), "ii": 741}
Li [2] ['k2'] ["qq"]-- > {11pr 22 pm 33}
Tuple tuple
A, create and transform
T = (11, 22, 22, 33)
T = tuple ((11, 22, 33))
T = tuple {[]} # string, list, dictionary
B. unique methods
Count index
C, nesting (elements cannot be modified)
T = (11, 22, 22, 33)
T = (112.22, ["zq", {"zq1": "Z1"}])
T [2] = ["zq", {"zq1": "Z1"}]
T [2] [1] = {"zq1": "Z1"}
T [2] [1] ["zq1"]
E, the properties of tuples can not be modified, who can not be modified-the elements of tuples cannot be modified, and the elements of elements can be modified.
# add new elements to the elements in the dictionary, two ways
Dic = {"zq1": "zz"}
# dic.update ({"zq2": 15}) # pay attention to enlarge parentheses for newly added elements
# print (dic)
Dic ["zq2"] = 15
Print (dic)
# t = (11, 22, 22, 33)
T = (112.22, ["zq", {"zq1": "Z1"}])
# print (t [2])
# print (t [2] [1])
# print (t [2] [1] ["zq1"])
# print (t)
# t [2] .append ("zz")
# print (t)
T = (112.22, ["zq", {"zq1": "Z1"}])
T [2] [1] ["zq2"] = 15
Print (t)
T [2] [1] .update ({"zq3": 15})
Print (t)
# when does it change itself? when does it produce a new one?
# General operations on strings
General string, perform a function, generate a new content, the original content remains unchanged
List, tuple, dic, perform a function and change itself
Dictionary:
1. Create
A = {"Z1": 8}
A = dict ()
Li = [11, 22, 22, 33]
# new_dict = dict (li) # this is not allowed
# new_dict = dict (enumerate (li,10))
New_dict = dict (enumerate (li,1))
Print (new_dict)
# if you want to convert the list, you can only use enumerate
two。 The internal functions of dictionaries
Dic = {"K1": 123,456, "K3": 566}
# method, no @ staticmothod, object. Method
# dic.get ()
# K1 and K2. Default is 123.
# method, with @ staticmothod, class. Method
# n = dic.fromkeys (['K1BQ / K2MJ / K3'], "123")
The function of # fromkeys is to find the key value that exists in the dictionary and reassign it.
# n = dict.fromkeys (['K1BQ / K2MJ / K3'], "123")
# print (n)
N = dict.fromkeys (['K1BZ, K2MJ, K3'], [])
Print (n)
N ['K1'] .append (' x')
Print (n)
This is the end of this article on "basic knowledge points of python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.