Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the skills of Python coding

Shulou Source: shulou.com Published: 2022-06-01 19:30:44 10月15日 Update

This article mainly introduces "what are the skills of Python coding". In the daily operation, I believe that many people have doubts about the skills of Python coding. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "what are the skills of Python coding?" Next, please follow the editor to study!

1 、 isinstance

The isinstance function can be used to determine the type of instance, but its second argument can be a tuple of multiple data types. For example:

Isinstance (x, (int, float))

# is equivalent to

Isinstance (x, int) or isinstance (x, float)

Similar functions include string startswith methods and endswith methods, such as:

S.startswith ('','')

# is equivalent to

S.startswith ("'") or s.startswith (") 2. Share files with http.server # python3

Python3-m http.server

# python2

Python-m SimpleHTTPServer

As shown in the following figure, it is convenient to share files on the local area network through the browser.

3. Zip function implements dictionary key-value pair interchange > lang = {"python": ".py", "java": ".java"}

> dict (zip (lang.values (), lang.keys ()

{'.java': 'java',' .py': 'python'} 4, find the number that appears most frequently in the list [1, 2, 3, 4, 2, 2, 3, 1, 4, 4, 4, 5]

> > max (set (test), key=test.count)

45. Use _ _ slots__ to save memory class MyClass (object):

Def _ _ init__ (self, name, identifier):

Self.name = name

Self.identifier = identifier

Self.set_up ()

Print (sys.getsizeof (MyClass))

> 1016

Class MyClass (object):

_ _ slots__ = ['name',' identifier']

Def _ _ init__ (self, name, identifier):

Self.name = name

Self.identifier = identifier

Self.set_up ()

Print (sys.getsizeof (MyClass))

> 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!

Tags: Skills coding learning functions methods files more equivalence types help utility next memory parameters multiple dictionaries characters strings instances local Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Linux Xiaomi Huawei NVidia