In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to get started with python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Multiplication table for i in range (1): for j in range (1): print (str (j) + "*" + str (I) + "=" + str (I * j), end='\ t') print ()
List
# list insertion operation lis = [12Power32, 232pyrr123, 1234, 12345, 12345, 12346] lis1 = lis [2:5:1] # slicing operation start end step size list1.appand (100) # add an element list2 = [1234 12346Magi 6456] list1.extend (list2) # add multiple elements to the end of the list list1.insert (1Magi 90) # add elements anywhere in the list # Delete list elements lst = [12334 5356 2345] lst.remove (30) # remove 30lst.pop from the list (1) # Delete lst according to index [1:3] = [] # slice delete lst.clear () del lst# list sort list = [123meme345236gentin 254576jue 3454 mine234p5 6] list.sort (reverse = true) # descending Instead of generating new objects, change new_list = sorted (list) # on the original list to generate a new list # list generative lst = [i for i in range (1Jing 10)]
Dictionary (key-value pairs, unordered sequences)
# create a dictionary scores = {'Zhang San': 100,200} student = dict (name = 'jack', age = 20) scores.get (' Zhang San', 99) # more secure, do not return None if you cannot find it, and will not report an error. 99 refers to the default del scores ['Zhang San'] # delete the ergodic for item in scorces of the specified key value pair # dictionary element in the dictionary: print (item,scores [item]) # dictionary generative items = ['fruits','sss','qqq'] prices = [234 item:price for item, price in zip (items, prices)} tuple (immutable sequence) # tuple creation t = (' python', 'ss') 978) # you can omit parentheses To contain only one element, you need to add a comma T2 = ('asdf',) T1 = tuple ((' python', 'ss', 978)). Generation of the collection # the elements in the collection are not allowed to repeat s = set (range (6)) s = set. 3 ins 4]) # using set to convert data of list, tuple, and string types into a collection s = set () # define an empty collection # New operation of the collection print (10) # in not ins.add (12) # add an element to the collection s.update ({12 ins 4, 534, 53}) # update at least one element at a time Delete operation of list and tuple # collection s.remove (12) # Delete an element in the collection s.discard (12) # if there is no such element in the collection will not report an error s.pop () # No parameter s.clear () # relation between sets S1 = = s judge whether two sets are equal b.issubset (a) # b is a subset of a whether a.issuperset (b) # an is a superset a.isdisjoin of b (B) whether two sets intersect # Mathematical operation s1.intersection (S2) # returns intersection and & operator s1.union (S2) # Union operation and | operator same s1.difference (S2) # difference operation and-operator s1.symetric_difference (S2) # symmetric difference Remove the same set of elements to generate the formula s = {i for i in range (6)} string
Residency means sharing one memory space
Pycharm is optimized. The same string is the same object.
# query operation for # string s = 'hello,hello's.index (' lo') # 3s.find ('lo') # 3 does not throw an exception s.rfind (' lo') # 9 Last occurrence # case conversion upper () lower () # alignment operation s.center (20revisors') # Center alignment Fill in * s.ljust () # left alignment # string split s = s.split (sep ='|', maxsplit = 1) # default delimiter is space rsplit () # replace # string split from the right s = 'hello python's.replace (' python', 'java',4) # replace python with java The maximum number of replacements is 4'*'.join ('python') # returns p*y*t*h*o*nt = (' hello', 'java',' python')''.join (t) # slice operation s = S1 [1:5:1] # truncates from 1 to 4, step size 1s = S1 [:: 2] default starts at 0 Step to format the string print ('I am $s'% (name))'my name is {0}. This year {1} years old '.format (name,age) print (' d'% 99) # 10 represents the width # string encoding byte = s.encode (encoding = 'GBK') # UTF-8 encoding print (byte.decode (encoding =' GBk')) # decoding # string slicing operation s = S1 [1:5:1] # truncated from 1 to 4, step size 1s = S1 [:: 2] default starts at 0 Step to format the string print ('I am $s'% (name))'my name is {0}. This year {1} year old '.format (name,age) print (' d'% 99) # 10 represents the width # string encoding byte = s.encode (encoding = 'GBK') # UTF-8 encoding print (byte.decode (encoding =' GBk')) # Decoding the above is the quick start to python shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis for understanding. If you want to know more about it, you are welcome to follow the industry information channel.
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.