Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the minor problems that Python needs to pay attention to?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what are the minor problems that Python needs to pay attention to". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what are the minor problems that need to be paid attention to in Python?"

1 python always records the latest value of the variable.

2 variables should be short and descriptive, such as student_name, etc.

(3) lowercase is recommended for variable names.

4 enclosed in single and double quotation marks, the string can contain quotation marks and apostrophes. Usage: "this's a cup"

5 title () changes the first letter of each word to capitalization. Usage: str.title ()

6 upper () converts the string to uppercase. Usage: str.upper ()

7 lower () converts the string to lowercase. Usage: str.lower ()

8 Whitespace generally refers to any non-printed character. Such as spaces, tabs, and line breaks.

9 rstrip () removes the white space at the end of the string. Usage: str.rstrip ()

10 lstrip () removes the white space at the beginning of the string. Usage: str.lstrip ()

11 strip () removes the white space at both ends of the string. Usage: str.strip ()

12 Python uses two titles to represent the multiplier. Usage: 3 * 2

13 programming concept. The Zen of Python: import this

14 list uses commas to split the elements.

The 15 list index-1 returns the last list of elements,-2, and so on. Usage: list [- 3:]

16 list [0] = 'update' modify list element

17 add elements to the list.append ('add') list

Insert elements at the specified location in the 18 list.insert (0. 0 insert') list

19 del list [0] del element Delete list element

20 newlist = list.pop () method pop () deletes the element

21 remove the element from the list and no longer use the del method. After deleting the element, it is possible to select pop ()

22 list.remove ('element') removes the first specified element based on the value, and can then be used.

The 23 sort () list is permanently sorted alphabetically. Such as: list.sort ()

The 24 sort () list is sorted in reverse alphabetical order. Such as: list.sort (reverse=True)

25 reverse () reverses the sort of list elements. Usage: list.reverse ()

Select a meaningful name when traversing the 26 for loop. Usage: for cat in cats:

27 range () generates a series of numbers. Usage: numbers= list (range (1d11))

28 list built-in statistical function. Usage: min (list) / max (list) / sum (list)

Slicing function of 29 python. Usage: list [0:3] / list [:] / list [- 3:] / list [: 9]

30 list replication. Usage: new_foods = old_food [:]

The 31 tuple consists of a list of elements that cannot be modified and are identified by parentheses. Usage: tulple = (2BI 3)

Case is not taken into account when checking for equality. Usage: str.lower () = = 'somestr'

33 use and to check multiple conditions. Usage: condition1 > = 1 and condition2 > = 2 and.

34 use or to check multiple conditions. Usage: condition1 > = 1 or condition2 > = 2 or.

35 use multiple lists. Usage:

List1 = ['1, 2, 3, 4, 4]

List2 = ['1m 4']

For l2 in list2:

If l2 in list1:

Go ()

Else:

Pass

36 A space is added on both sides of the comparison operator to facilitate readability. Usage: if age > 40:

37 dict modified value, usage: dict ['key'] = value

38 dict delete key-value pair, usage: del dict ['key']

39 ergodic dictionary, usage:

For key,value in dict.items ():

For key in dict:

For key in dict.keys ():

For value in dict.values ():

For value in set (dict.values ()): # No duplicate values of the traversal dictionary

40 list of dictionaries, usage:

Dict1 = ['key1':'values1','key2':'values2']

Dict2 = ['key1':'values3','key2':'values4']

Dict3 = ['key1':'values5','key2':'values6']

Dicts = [dict1,dict2,dict3]

For dict in dicts:

Pass

41 storing lists in dictionaries, usage:

Dict1 = {'key1':'values1','key2': [' values1','values2']}

For dict in dict1 ['key2']:

42 Dictionaries are stored in dictionaries, usage:

Dicts = {

'keys1': {'key1':'values1','key1':'values2''key1':'values3'}

'keys2': {'key2':'values2','key2':'values2''key2':'values3'}

}

43 input receives user input, usage:

Message = input ('user input some valuations')

44% modular operation to judge parity, usage:

If (4% 3) = = 0:

Print ('even'):

Else:

Print ('Odd')

General usage of the 45 while loop:

Current_number = 1

While current_number

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report