Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Python Data Type: String, Number, List, Tuple, Set and Dictionary

Explore Python Data Type: String, Number, List, Tuple, Set and Dictionary with clear explanations, practical examples, and useful tips.

Table of Contents

This guide covers python data type: string, number, list, tuple, set and dictionary with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.

In the previous section, we became familiar with the first Python Program, adding two numbers and printing their sum out of the screen. In this section, you will learn how to use Python as a computer, learn numbers, strings, lists and take the first step towards Python programming.

Because the article will list the most important content of all data types in Python, it will be quite long. Each data type comes with a specific example so you can easily imagine.

Make sure you save this Python Document Page to update the latest articles. Don't forget to do Python exercises to reinforce your knowledge.

Variables are a location in memory used to store data (values). The variable is uniquely named to distinguish between different memory locations. The rules for writing a variable name are the same as the rules for writing identifiers in Python.

In Python, you don't need to declare the variable before using it, just assign a variable a value and it will exist. There is also no need to declare variable type, the variable type will be automatically received based on the value you assigned to the variable.

Assign values to variables:

To assign a value to the variable, use the = operator. Any kind of value can be assigned to a valid variable.

For example:

hoa = "H?ng" la = 3 canh = 5.5

Above are three assignment statements, "Pink" is a character string, assigned to the flower variable, 3 is an integer and is assigned to la, 5. 5 is a decimal number and assigned to the soup.

Assign multiple values:

In Python you can perform multiple assignments in a command like this:

hoa, la, canh = "H?ng", 3, 5.5

If you want to assign the same value to multiple variables, you can write the following command:

hoa, la, canh = 3

The above command will assign a value of 3 to all three variables, flowers, la and soup.

Python supports integers, decimals, and complex numbers, which in turn are defined as int, float, and complex classes in Python. Integers and decimals are distinguished by the presence or absence of the decimal point. For example: 5 is an integer, 5. 0 is a decimal number. Python also supports complex numbers and uses the suffixjorJTo indicate the virtual part. For example:3+5j. In addition tointAndfloat, Python supports two more types of numbers,DecimalAndFraction.

We will use the type () function to check which variable or value belongs to the class and isinstance () to check if they belong to any particular class.

a = 9 # Output: print(type(a)) # Output: print(type(5.0)) # Output: (10+2j) b = 8 + 2j print(b + 2) # Ki?m tra xem b có ph?i là s? ph?c không # Output: True print(isinstance(b, complex))a = 9 # Output: print(type(a)) # Output: print(type(5.0)) # Output: (10+2j) b = 8 + 2j print(b + 2) # Ki?m tra xem b có ph?i là s? ph?c không # Output: True print(isinstance(b, complex))a = 9 # Output: print(type(a)) # Output: print(type(5.0)) # Output: (10+2j) b = 8 + 2j print(b + 2) # Ki?m tra xem b có ph?i là s? ph?c không # Output: True print(isinstance(b, complex))

Python integers are not limited to lengths, decimals are limited to 16 numbers after the decimal point.

The numbers they work on are usually a factor of 10, but computer programmers (usually embedded programmers) need to work with binary, hexadecimal and octal systems. To represent these coefficients in Python, we put an appropriate prefix before that number.

Coefficient prefix for Python numbers:

Number system Binary Prefix '0b' or '0B' Octal system '0o' or '0O' Hexadecimal '0x' or '0X'

(You put the prefix but no sign ").

Here is an example of using coefficient prefixes in Python, and when using the print () function to print their values to the screen, we get the corresponding number in the factor of 10.

# Output: 187 print(0b10111011) # Output: 257 (250 + 7) print(0xFA + 0b111) # Output: 15 print(0o17)

You can convert this number type to another number. This is also called coercion. Operations such as addition and subtraction will implicitly convert integers to decimal numbers (automatically) if there is an operator in the operation that is a decimal.

For example: If you perform the addition of integer 2 and decimal number 3. 0, then 2 will be forced to convert into decimal 2. 0 and the result will be a 5. 0 decimal.

>>> 2 + 3.0 5.0

You can use built-in Python functions like int (), float () and complex () to switch between numeric types explicitly. These functions can even be converted from strings.

>>> int(3.6) 3 >>> int(-1.2) -1 >>> float(7) 7.0 >>> complex('2+8j') (2+8j)

When converting from decimal to integer, the number will be dropped, only the integer part is taken.

The built-in float class in Python can surprise us a bit. Normally, if calculating 1. 1 and 2. 2, we think the result will be 3. 3, but it doesn't seem to be so. If you check the correctness and error of this operation in Python, the result will be False.

>>> (1.1 + 2.2) == 3.3 False

What happened?

This is because decimal numbers are implemented in computer hardware in the form of binary fractions, because computers only understand binary numbers (0 and 1), so most of the decimal fraction we know, cannot be stored correctly in the computer.

For example, we cannot represent 1/3 fraction as a decimal number, since it is an infinite decimal number, with numbers after the decimal point infinitely long, we can only estimate it. .

When converting decimal 0. 1, it will lead to infinitely long binary part of 0. 000110011001100110011. And the computer only stores part of the finite number after the sign. Its just. Therefore, the stored number is only approximately 0. 1 but never equal to 0. 1. That is why, the addition we mentioned above does not produce the results we expect. That is the limit of computer hardware, not Python error.

Now try typing the addition above into Python to see what the result is:

>>> 1.1+2.2 3.3000000000000003

To fix this problem, we can use the Python Decimal module. While the float only takes 16 digits after the decimal point, the Decimal module allows to customize the length of the number.

import decimal # Output: 0.1 print(0.1) # Output: 0.1000000000000000055511151231257827021181583404541015625 print(decimal.Decimal(0.1))

This module is used when we want to perform operations with decimal numbers to get the results we have learned at school.

This is also quite important, for example 25. 50kg will be more accurate than 25. 5kg, because 2 decimal places are still more accurate than 1 digit.

from decimal import Decimal # Output: 3.3 print(Decimal('1.1') + Decimal('2.2')) # Output: 10.000 print(Decimal('4.0') * Decimal('2.50'))

If you want a more concise code, you can enter the Decimal module and edit the module name to D.

from decimal import Decimal as D # Output: 3.3 print(D('1.1') + D('2.2')) # Output: 10.000 print(D('4.0') * D('2.50'))

In this code, enter the Decimal module and edit its name to D, the result is unchanged from the above code.

You can ask in the multiplication section, why not use Decimal number to multiply it by adding 0 after 4 and 2. 5. The answer is efficiency, operations with floats are faster than Decimal operations.

We often use Decimal in the following cases:

  • When creating a financial app, it is necessary to represent the decimal part exactly.
  • When you want to control the accuracy of numbers.
  • When you want to do the math just like you did at school.

Python provides fractions related to fractions through fractions modules. A fraction with a numerator and denominator, both are integers. We can create Fraction objects in many different ways:

import fractions # T?o phân s? t? s? th?p phân print(fractions.Fraction(4.5)) # Output: 9/2 # T?o phân s? t? s? nguyên # Code by TipsMake.com print(fractions.Fraction(9)) # Output: 9 # T?o phân s? b?ng cách khai báo t?, m?u s? print(fractions.Fraction(2,5)) # Output: 2/5

When creating fractions from floats, we can get unusual results, which is due to computer hardware limitations as discussed in the decimal module.

In particular, you can initialize a fraction from the string. This is the preferred initialization method when using decimal numbers.

import fractions # Kh?i t?o phân s? t? float print(fractions.Fraction(0.1)) # Output: 3602879701896397/36028797018963968 # Kh?i t?o phân s? t? string # Code by TipsMake.com print(fractions.Fraction('0.1')) # Output: 1/10

Fraction data types fully support basic operations such as addition, subtraction, multiplication, division and logic:

# Output: 1 print(F(2,5) + F(3,5)) # Output: 3/5 print(F(2,5) + F(1,5)) # Output: 7/1 print(1 / F(3,7)) # Output: False print(F(-2,9) > 0) # Output: True print(F(-2,9) < 0)

Python provides math and random modules to solve other math problems such as trigonometry, logarithm, probability and statistics, etc. Since the math module has many functions and attributes, I calculated will do a separate article to list them. Below is an example of math in Python.

from fractions import Fraction as F import math # Output: 3.141592653589793 print(math.pi) # Output: -1.0 print(math.cos(math.pi)) # Output: 22026.465794806718 print(math.exp(10)) # Output: 2.0 print(math.log2(4)) # Output: 1.1752011936438014 print(math.sinh(1)) # Output: 40320 print(math.factorial(8))

The interpreter acts as a simple calculator: You can enter a calculation and it will write the value. Expression syntax is straightforward: operators like +, -, * and / work like most other programming languages (Pascal, C), parentheses () can be used to group. For example:

>>> 2 + 2 4 >>> 50 - 5*6 20 >>> (50 - 5*6) / 4 5.0 >>> 8 / 5 # phép chia luôn tr? v? m?t s? d?ng th?p phân v?i d?u ch?m 1.6

Integers (eg2,4,20) are of typeint, decimal numbers (such as5.0,1.6) are of typefloat.

Divide (/) always returns type float. To perform the partial division (remove the numbers after the decimal point) you can use the operator//; To calculate the remainder, use%As the example below:

>>> 17 / 3 # phép chia th??ng tr? v? s? th?p phân 5.666666666666667 >>> >>> 17 // 3 # phép chia l?y s? nguyên, lo?i b? ph?n sau d?u th?p phân 5 >>> 17 % 3 # toán t? % tr? v? s? d? c?a phép chia 2 >>> 5 * 3 + 2 # th??ng * s? chia + s? d? 17

With Python, you can use the**Operator to calculate the exponent:

>>> 5 ** 2 # 5 bình ph??ng 25 >>> 2 ** 7 # 2 m? 7 128

The equal sign=Is used to assign a value to a variable. After that, no results will be displayed before the next command prompt:

>>> width = 20 >>> height = 5 * 9 >>> width * height 900

If a variable is not defined (assign value), try to use that variable, you will get the following error:

>>> n # b?n ?ang c? truy c?p vào bi?n n ch?a ???c gán giá tr? Traceback (most recent call last): File "", line 1, in NameError: name 'n' is not defined

Python fully supports floating point, the calculation has both integers and decimals, the result will return the number in decimal (verb: operator with mixed type operand converts integer operand to decimal):

>>> 4 * 3.75 - 1 14.0

In interactive mode, the last printed expression will be assigned to variable_, making it easier to perform further calculations. For example:

>>> tax = 12.5 / 100 >>> price = 100.50 >>> price * tax 12.5625 >>> price + _ 113.0625 >>> round(_, 2) 113.06

You should treat this variable as read-only, do not assign a value to it - because creating a variable of the same name will take up this default variable and no longer do good things like that.

String in Python is a sequence of characters. Computers do not handle characters, they only work with binary numbers. Although you can see the characters on the screen, they are stored and processed internally as a combination of numbers 0 and 1. Converting the numeric character is called encoding and the reverse process called decoding. ASCII and Unicode are 2 of the commonly used common encodings.

In Python, string is a sequence of Unicode characters. Unicode includes all characters in all languages and provides uniformity in encoding.

Besides numbers, Python can also manipulate strings, represented in many ways. They can be put in single quotes ('.') or double (".") with the same result.Used to "escape" these 2 quotes.

>>> 'spam eggs' # d?u nháy ??n 'spam eggs' >>> 'doesn't' # s? d?ng ' ?? vi?t d?u nháy ??n. "doesn't" >>> "doesn't" # .ho?c s? d?ng d?u nháy kép "doesn't" >>> '"Yes," he said.' '"Yes," he said.' >>> ""Yes," he said." '"Yes," he said.' >>> '"Isn't," she said.' '"Isn't," she said.'

In the interactive interpreter, the result string consists of a quotation mark and special "escape" characters used. Although the output looks a bit different from the input (the enclosed quotes may change), these two strings are equivalent. The string is written in quotation marks when the string contains single quotes and no double quotes, otherwise it will be written in single quotes. The print () function creates a more readable output string, by skipping the apostrophe enclosed and printing special characters, "hiding" the quotes:

>>> '"Isn't," she said.' '"Isn't," she said.' >>> print('"Isn't," she said.') "Isn't," she said. >>> s = 'First line.nSecond line.' # n ngh?a là dòng m?i >>> s # không có print(), n s? ???c vi?t trong k?t qu? ??u ra 'First line.nSecond line.' >>> print(s) # có print(), n s? t?o ra dòng m?i First line. Second line.

If you do not want the characters added byInterpreted by the interpreter as a special character, use the raw string by addingrTo the first quotation mark:

>>> print('C:somename') # ? ?ây n là dòng m?i! C:some ame >>> print(r'C:somename') # thêm r tr??c d?u nháy C:somename

String strings can be written on multiple lines by using 3 quotes:"""."""or'''.'''. End lines automatically included in the string, but can prevent this by addingAt the end of the line. For example:

print(""" Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """)

This is the result (the new original line is not counted):

Here is a list of all escape sequences supported by Python:

Escape SequenceLayewewline Backslash and new line are ignored Backslash 'Single quotation mark' Double quotes a

ASCII Bell

B ASCII Backspace f ASCII Formfeed n ASCII Linefeed r ASCII Carriage Return t ASCII Horizontal Tab v ASCII Vertical Tab ooo The character has an octal value ooo xHH The hexadecimal character is HH

For example: Run each command individually in the compiler to see your results.

>>> print("C:Python32TipsMake.com") C:Python32TipsMake.com >>> print("In dòng nàynthành 2 dòng") In dòng này thành 2 dòng >>> print("In giá tr? x48x45x58") In giá tr? HEX >>>

Strings can be indexed with the first character numbered 0. There is no separate character type, each character is simply a number:

>>> word = 'Python' >>> word[0] # ký t? ? v? trí s? 0 'P' >>> word[5] # ký t? ? v? trí s? 5 'n'

Index can also be negative, start counting from the right:

>>> word[-1] # last character 'n' >>> word[-2] # second-last character 'o' >>> word[-6] 'P'

Note that since -0 is similar to 0, negative indicators start at -1.

In addition to numbering, slices are also supported. While the index is used to retrieve individual characters, slices will allow you to retrieve substring:

>>> word[0:2] # các ký t? t? v? trí 0 (bao g?m) ??n 2 (lo?i tr?) 'Py' >>> word[2:5] # các ký t? t? v? trí 2 (bao g?m) ??n 5 (lo?i tr?) 'tho'

Notice how the characters are retained and excluded. It always ensures thats[:i] + s[i:]Equal tos:

>>> word[:2] + word[2:] 'Python' >>> word[:4] + word[4:] 'Python'

The index in the chain cut has a pretty default setting, there are 2 indexes that are ignored by default, 0 and the size of the cut string.

>>> word[:2] # các ký t? t? ??u ??n v? trí th? 2 (lo?i b?) 'Py' >>> word[4:] # các ký t? t? v? trí th? 4(l?y) ??n h?t 'on' >>> word[-2:] # các ký t? th? hai tính t? cu?i lên (l?y) ??n h?t 'on'

Another way to remember how to cut the work sequence is to visualize the indicators as partitions between characters, with the leftmost character being numbered 0. Then, the last character on the right, in string n characters will have an index n, for example:

+---+---+---+---+---+---+ | P | y | t | h | o | n | +---+---+---+---+---+---+ 0 1 2 3 4 5 6 -6 -5 -4 -3 -2 -1

The first row of numbers brings the position of the index from 0 to 6 in the series. The second row is the corresponding negative indicators. When cutting from i to j will include all characters between i and j, respectively.

For non-negative indicators, the length of a slice is the difference of the indicators, if both are within the limit. For example, the length of Word [1: 3] is 2.

Trying to use an index that is too large will return an error:

>>> word[42] # t? ch? có 6 ký t? Traceback (most recent call last): File "", line 1, in IndexError: string index out of range

However, indexes outside the slice range are still handled neatly when used to cut:

>>> word[4:42] # c?t ký t? t? v? trí th? 4 ??n 42 'on' >>> word[42:] # c?t ký t? sau v? trí 42 ''

Python strings cannot be changed - they are fixed. Therefore, if you intentionally assign a character to an indexed location, you will receive an error message:

>>> word[0] = 'J' . TypeError: 'str' object does not support item assignment >>> word[2:] = 'py' . TypeError: 'str' object does not support item assignment

If another string is needed, the best way is to create a new one:

>>> 'J' + word[1:] 'Jython' >>> word[:2] + 'py' 'Pypy'

You cannot delete or remove characters from the string, but like tuple, you can delete the entire string, using the del keyword:

qtm_string = 'tipsmake.com' del qtm_string # Output: NameError: name 'qtm_string' is not defined qtm_string

Strings can be joined together by the+Operator and replaced by*:

>>> # thêm 3 'un' vào sau 'ium' >>> 3 * 'un' + 'ium' 'unununium'

Two or more characters in the form of strings (ie, characters in the quotes) are joined automatically.

>>> 'Py' 'thon' 'Python'

This feature only works with string literal, not with variables or expressions:

>>> prefix = 'Py' >>> prefix 'thon' # không th? n?i m?t bi?n v?i m?t chu?i . SyntaxError: invalid syntax >>> ('un' * 3) 'ium' . SyntaxError: invalid syntax

If you want to join variables together or variables with strings, use the+Sign:

>>> prefix + 'thon' 'Python'

This feature is especially useful when you want to break long strings into shorter strings:

>>> text = ('Put several strings within parentheses ' . 'to have them joined together.') >>> text 'Put several strings within parentheses to have them joined together.'

If you want to join strings in many different lines, use parentheses:

>>> # s? d?ng () >>> s = ('Xin ' . 'chào!') >>> s 'Xin chào!'

Like list and tuple, you also use the for loop when you need to loop through a string, like for example counting the number of "i" characters in the following string:

count = 0 for letter in 'TipsMake.com': if(letter == 'i'): count += 1 # Output: Có 1 ch? i ???c tìm th?y print('Có', count,'ch? i ???c tìm th?y')

To check if a substring is in the string, use the keyword print, as follows:

>>> 'tipsmake' in 'tipsmake.com' True >>> 'python' in 'tipsmake.com' False >>>

There are two most common functions when working with strings in Python: enumerate () and len ().

Thelen()Function is built into Python, which returns the length of the string:

>>> s = 'supercalifragilisticexpialidocious' >>> len(s) 34

The enumerate () function returns the listed object, containing the value and index pairs of the element in the string, which is quite useful while looping.

qtm_str = 'Python' # enumerate() qtm_enum = list(enumerate(qtm_str)) # Output: list(enumerate(qtm_str) = [(0, 'P'), (1, 'y'), (2, 't'), (3, 'h'), (4, 'o'), (5, 'n')] print('list(enumerate(qtm_str) = ', qtm_enum)

The format () method is very flexible and powerful when used to format strings. The string format contains the {} mark as a placeholder or a replacement field to receive the replacement value. You can also use position or keyword arguments to specify the order.

# default(implicit) order thu_tu_mac_dinh = "{}, {} và {}".format('Qu?n','Tr?','M?ng') print('n--- Th? t? m?c ??nh ---') print(thu_tu_mac_dinh) # s? d?ng ??i s? v? trí ?? s?p x?p th? t? vi_tri_thu_tu= "{1}, {0} và {2}".format('Qu?n','Tr?','M?ng') print('n--- Th? t? theo v? trí ---') print(vi_tri_thu_tu) # s? d?ng t? khóa ?? s?p x?p th? t? tu_khoa_thu_tu = "{s}, {b} và {j}".format(j='Qu?n',b='Tr?',s='M?ng') print('n--- Th? t? theo t? khóa ---') print(tu_khoa_thu_tu)

We have the results when running the above code as follows:

--- Th? t? m?c ??nh --- Qu?n, Tr? và M?ng --- Th? t? theo v? trí --- Tr?, Qu?n và M?ng --- Th? t? theo t? khóa --- M?ng, Tr? và Qu?n

The format () method can have optional format specifications. They are separated from the field name with a: . For example, you can align left <, right> or center ^ a string in the given space. It is possible to format integers such as binary and hexadecimal numbers; Decimals can be rounded or displayed in exponential form. There are many formats you can use.

>>> # ??nh d?ng s? nguyên >>> "Khi chuy?n {0} sang nh? phân s? là {0:b}".format(12) 'Khi chuy?n 12 sang nh? phân s? là 1100' >>> # ??nh d?ng s? th?p phân >>> "S? th?p phân {0} ? d?ng m? s? là {0:e}".format(1566.345) 'S? th?p phân 1566.345 ? d?ng m? s? là 1.566345e+03' >>> # Làm tròn s? th?p phân >>> "1 ph?n 3 là: {0:.3f}".format(1/3) '1 ph?n 3 là: 0.333' >>> # c?n ch?nh chu?i >>> "|{:<10}|{:^10}|{:>10}|".format('Qu?n','Tr?','M?ng') '|Qu?n | Tr? | M?ng|'

Old style string format:

You can format the string in Python about sprintf () style used in programming language C with% operator.

>>> x = 15.1236789 >>> print('Giá tr? c?a x là %3.2f' %x) Giá tr? c?a x là 15.12 >>> print('Giá tr? c?a x là %3.4f' %x) Giá tr? c?a x là 15.123712.3457

There are many methods built into Python to work with strings. In addition to the format () mentioned above, there is lower (), upper (), join (), split (), find (), replace (), etc. .

Python provides a variety of complex data, often called sequences, used to group different values. The most versatile is the list (list).

In Python, the list is represented by a series of values, separated by commas, within []. Lists may contain multiple items of different types, but usually items with the same type.

>>> squares = [1, 4, 9, 16, 25] >>> squares [1, 4, 9, 16, 25]

List unlimited number of items, you can have many different data types in the same list, such as string, integer, decimal, .

list1 = [] # list r?ng list2 = [1, 2, 3] # list s? nguyên list3 = [1, "Hello", 3.4] # list v?i ki?u d? li?u h?n h?p

You can also create nested lists (lists contained in the list), for example:

a = ['a', 'b', 'c'] n = [1, 2, 3] x = [a, n] print (x) # Output: [['a', 'b', 'c'], [1, 2, 3]] print (x[0]) # Output: ['a', 'b', 'c'] print(x[0][1]) # Output: b

Or declare a nested list from the beginning:

list4 = [mouse", [8, 4, 6], ['a']]

There are many different ways to access the element of a list:

Index (index) of the list:

Use the index [] operator to access an element of the list. Index starts at 0, so a list with 5 elements will have an index of 0 to 4. Accessing an index element other than the index of the list will give rise to an IndexError error. Index must be an integer, cannot use float, or other data type, will create a TypeError error.

qtm_list = ['q','u','a','n','t','r','i','m','a','n','g','.','c','o','m'] # TypeError: list indices must be integers or slices, not float # TypeError: index c?a list ph?i là s? nguyên ho?c slice, không ph?i s? th?p phân qtm_list[2.0]

Nested lists can be accessed by nested index:

qtm_list = ['q','u','a','n','t','r','i','m','a','n','g','.','c','o','m'] # Output: q print(qtm_list[0]) # Output: a print(qtm_list[2]) # Output: t print(qtm_list[4]) # List l?ng nhau ln_list = ["Happy", [1,3,5,9]] # Index l?ng nhau # Output: a print(ln_list[0][1]) # Output: 9 print(ln_list[1][3])

Negative Index:

Python allows negative indexing for strings. Index -1 is the last element, -2 is the last element from the last. Simply said, index is negative when you count the element of the string backwards from the beginning to the beginning.

qtm_list = ['q','u','a','n','t','r','i','m','a','n','g','.','c','o','m'] # Code by TipsMake.com # Output: m print(qtm_list[-1]) # Output: i print(qtm_list[-9])

Python allows access to a range of elements of the list by using the slice operator: (colon). Every list cut action returns a new list containing the required elements.

qtm_list = ['q','u','a','n','t','r','i','m','a','n','g','.','c','o','m'] # Code by TipsMake.com # Output: ['u', 'a', 'n', 't'] print(qtm_list[1:5]) # Output: ['q', 'u', 'a', 'n', 't', 'r', 'i'] print(qtm_list[:-8]) # Output: ['n', 'g', '.', 'c', 'o', 'm'] print(qtm_list[9:])

To slice the list, you only need to use the sign: between the two indexes to retrieve the elements. [1: 5] will take elements 1 to 5, [: -8] taken from 0 to -8, .

If the following cut action is performed, it will return a new list as a copy of the original list:

qtm_list = ['q','u','a','n','t','r','i','m','a','n','g','.','c','o','m'] # Output: ['q', 'u', 'a', 'n', 't', 'r', 'i', 'm', 'a', 'n', 'g', '.', 'c', 'o', 'm'] print(qtm_list[:])

List also supports operations like list join:

>>> squares + [36, 49, 64, 81, 100] [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

Unlike strings, fixed, the list is a data type that can be changed. For example, you can change items in the list:

>>> cubes = [1, 8, 27, 65, 125] # có v? sai sai >>> 4 ** 3 # l?p ph??ng c?a 4 là 64, không ph?i 65! 64 >>> cubes[3] = 64 # thay th? giá tr? sai >>> cubes [1, 8, 27, 64, 125]

FAQ

What should I check before following these steps?

Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.

Why might the process not work?

Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.

Can I undo the changes if necessary?

That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.