Hướng dẫn what is variable in python ppt? - biến trong ppt python là gì?

Trình bày về chủ đề: "Các loại biến Python." - Bảng điểm trình bày:

1 loại biến Python Python Variable Types

2 Biếnvariables không có gì ngoài các vị trí bộ nhớ dành riêng được đặt tên để lưu trữ các giá trị. Điều này có nghĩa là khi bạn tạo một biến, bạn bảo lưu một số không gian trong bộ nhớ. Dựa trên loại dữ liệu của một biến, trình thông dịch phân bổ bộ nhớ và quyết định những gì có thể được lưu trữ trong bộ nhớ dành riêng. Do đó, bằng cách gán các loại dữ liệu khác nhau cho các biến, bạn có thể lưu trữ số nguyên, số thập phân hoặc ký tự trong các biến này. Variables Variables are nothing but named reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables.

3 Gán các giá trị cho các biến variablespython không phải được khai báo rõ ràng để dự trữ không gian bộ nhớ. Tuyên bố sẽ tự động xảy ra khi bạn gán một giá trị cho một biến. của toán tử = là tên của toán hạng variablethe ở bên phải của toán tử = là giá trị được lưu trữ trong biến. Ví dụ: Assigning Values to Variables
Python variables do not have to be explicitly declared to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign [=] is used to assign values to variables. The operand to the left of the = operator is the name of the variable The operand to the right of the = operator is the value stored in the variable. For example:

4 Ví dụ #! For example #!/usr/bin/python counter = 100 # An integer assignment
miles = # A floating point name = "John" # A string print counter print miles print name

5 Outputhere, 100 và "John" là các giá trị được gán cho & nbsp; Counter, & nbsp; Miles & nbsp; và & nbsp; tên & nbsp; output Here, 100, and "John" are the values assigned to counter, miles and name variables, respectively. running this program, this will produce the following result: 100 1000.0 John

6 Nhiều gán gán cho phép bạn gán một giá trị duy nhất cho một số biến đồng thời. Ví dụ: a = b = c = 1here, một đối tượng số nguyên được tạo với giá trị 1 và cả ba biến được gán cho cùng một vị trí bộ nhớ. Bạn cũng có thể gán nhiều đối tượng cho nhiều biến. Ví dụ: a, b, c = 1, 2, "John Hồi ở đây, hai đối tượng số nguyên có giá trị 1 và 2 được gán cho các biến A và B và một đối tượng chuỗi có giá trị" John "được gán cho biến C.A , b, c = 1, "John“# Chuyện gì xảy ra ở đây Multiple Assignment Python allows you to assign a single value to several variables simultaneously. For example: a = b = c = 1 Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables. For example: a, b, c = 1, 2, "john“ Here, two integer objects with values 1 and 2 are assigned to variables a and b, and one string object with the value "john" is assigned to the variable c. a, b, c = 1, "john“# WHAT HAPPENS HERE

7 Các loại dữ liệu tiêu chuẩn Dữ liệu được lưu trữ trong bộ nhớ có thể thuộc nhiều loại. Ví dụ, tuổi của một người được lưu trữ dưới dạng giá trị số được lưu trữ dưới dạng ký tự chữ và số có nhiều loại tiêu chuẩn khác nhau được sử dụng để xác định các hoạt động có thể trên chúng và Phương pháp lưu trữ cho mỗi người trong số họ. Standard Data Types The data stored in memory can be of many types.
For example, a person's age is stored as a numeric value address is stored as alphanumeric characters. Python has various standard types that are used to define the operations possible on them and the storage method for each of them. Python has five standard data types: Numbers String List Tuple Dictionary

8 Số Python 1 Kiểu số các loại dữ liệu Lưu trữ các giá trị số. Chúng là các loại dữ liệu bất biến, có nghĩa là thay đổi giá trị của một loại dữ liệu số dẫn đến một đối tượng được phân bổ mới. Các đối tượng đã được tạo khi bạn gán giá trị cho chúng. Ví dụ: var1 = 1Var2 = 10 Python Numbers 1 Number data types store numeric values.
They are immutable data types which means that changing the value of a number data type results in a newly allocated object. Number objects are created when you assign a value to them. For example: var1 = 1 var2 = 10

9 Số python 2you cũng có thể xóa tham chiếu đến một đối tượng số bằng cách sử dụng & nbsp; del & nbsp; statement.the cú pháp của câu lệnh DEL là: del var1 [, var2 [, var3 [...., varn]]] Xóa một đối tượng hoặc nhiều đối tượng bằng cách sử dụng câu lệnh DEL. Ví dụ: del var1 [, var2 [, var3 [...., varn]]]]] Python Numbers 2 You can also delete the reference to a number object by using the del statement. The syntax of the del statement is: del var1[,var2[,var3[....,varN]]]]You can delete a single object or multiple objects by using the del statement. For example: del var1[,var2[,var3[....,varN]]]]

10 Python hỗ trợ bốn loại số khác nhau [số nguyên đã ký] dài [số nguyên dài [cũng có thể được biểu diễn bằng bát phân và thập lục phân]] Python supports four different numerical types
int [signed integers] long [long integers [can also be represented in octal and hexadecimal]] float [floating point real values] complex [complex numbers]

11 Dưới đây là một số ví dụ về các số: intlongfloatcomplex10l0.03.14j100-0x19323l15.2045.j-7860122L -21.99.322E -36J0800XDEFABCECBDAECBAV 53E-7J Here are some examples of numbers:
int long float complex 10 L 0.0 3.14j 100 -0x19323L 15.20 45.j -786 0122L -21.9 9.322e-36j 080 0xDEFABCECBDAECBFBAEl 32.3+e18 .876j -0490 L -90. J -0x260 L -32.54e100 3e+26J 0x69 L 70.2-E12 4.53e-7j

12 chuỗi trong Python được xác định là một tập hợp các ký tự liên tục ở giữa các dấu ngoặc 0 Ở phần đầu của chuỗi và hoạt động theo cách của chúng từ -1 ở cuối. Dấu hiệu cộng [+] là toán tử nối chuỗi và dấu hoa thị [ *] là toán tử lặp lại. & NBSP; Strings Strings in Python are identified as a contiguous set of characters in between quotation marks. Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator [ [ ] and [ : ] ] with indexes starting at 0 in the beginning of the string and working their way from -1 at the end. The plus [+] sign is the string concatenation operator and the asterisk [ * ] is the repetition operator. 

13 Ví dụ: str = 'Xin chào thế giới!' In str # in hoàn chỉnh StringPrint str [0] # in ký tự đầu tiên của chuỗi str Str + "test" # in chuỗi được nối For example: str = 'Hello World!' print str # Prints complete string
print str[0] # Prints first character of the string print str[2:5] # Prints characters starting from 3rd to 5th print str[2:] # Prints string starting from 3rd character print str * # Prints string two times print str + "TEST" # Prints concatenated string

14 Điều này sẽ tạo ra kết quả sau: Xin chào Thế giới! This will produce the following result:
Hello World! H llo llo World! Hello World!Hello World! Hello World!TEST

15 danh sách danh sách là các loại dữ liệu tổng hợp linh hoạt nhất của Python. Danh sách chứa các mục được phân tách bằng dấu phẩy và được đặt trong các dấu ngoặc vuông [[]]. Các mục thuộc về danh sách có thể thuộc loại dữ liệu khác nhau. Các giá trị được lưu trữ trong danh sách có thể được truy cập bằng toán tử lát cắt [[] và [:]] với các chỉ mục bắt đầu từ 0 ở đầu List và hoạt động theo cách của chúng để kết thúc - 1. Dấu hiệu Plus [ +] là toán tử kết hợp danh sách và dấu hoa thị [ *] là toán tử lặp lại. Lists Lists are the most versatile of Python's compound data types.
A list contains items separated by commas and enclosed within square brackets [[]]. To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type. The values stored in a list can be accessed using the slice operator [[ ] and [ : ]] with indexes starting at 0 in the beginning of the list and working their way to end -1. The plus [ + ] sign is the list concatenation operator, and the asterisk [ * ] is the repetition operator.

16 Ví dụ: list = ['ABCD', 786, 2.23, 'John', 70.2] Tinylist = [123, 'John'] Danh sách in # In danh sách danh sách đầy đủ : 3] # Các yếu tố in bắt đầu từ danh sách thứ 2 đến 3rdprint [2:] For example: list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john'] print list # Prints complete list print list[0] # Prints first element of the list print list[1:3] # Prints elements starting from 2nd till 3rd print list[2:] # Prints elements starting from 3rd element print tinylist * 2 # Prints list two times print list + tinylist # Prints concatenated lists

17 đầu ra ['ABCD', 786, 2.23, 'John', 70.2] ABCD [786, 2.23] [123, 'John', 123, 'John'] ['ABCD', 786, 2.23, 'John', 70.2 , 123, 'John'] output ['abcd', 786, 2.23, 'john', 70.2] abcd [786, 2.23]
[123, 'john', 123, 'john'] ['abcd', 786, 2.23, 'john', 70.2, 123, 'john']

18 Tuplesa Tuple là một loại dữ liệu trình tự khác tương tự như danh sách. Một tuple bao gồm một số giá trị được phân tách bằng dấu phẩy. được đặt trong ngoặc [[]] và các yếu tố và kích thước của chúng có thể được thay đổi. Các mẫu được đặt trong ngoặc đơn [[]] và không thể thay đổi. Tuples có thể được nghĩ đến AS & nbsp; Danh sách chỉ đọc & nbsp; Tuples A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses []. The main differences between lists and tuples are: Lists are enclosed in brackets [[ ]] and their elements and size can be changed. tuples are enclosed in parentheses [ [ ] ] and cannot be changed. Tuples can be thought of as read-only lists.

19 Ví dụ Tuple = ['ABCD', 786, 2.23, 'John', 70.2] TinyTuple = [123, 'John'] In tuple # in toàn bộ danh sách [0] 3] # Các phần tử in bắt đầu từ thứ 2 đến 3rdprint tuple [2:] For example tuple = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinytuple = [123, 'john'] print tuple # Prints complete list print tuple[0] # Prints first element of the list print tuple[1:3] # Prints elements starting from 2nd till 3rd print tuple[2:] # Prints elements starting from 3rd element print tinytuple * 2 # Prints list two times print tuple + tinytuple # Prints concatenated lists

20 Điều này sẽ tạo ra kết quả sau :[ 'ABCD', 786, 2.23, 'John', 70.2] ABCD [786, 2.23] [2.23, 'John', 70.2] [123, 'John', 123, 'John' ] ['ABCD', 786, 2.23, 'John', 70.2, 123, 'John']] This will produce the following result:
['abcd', 786, 2.23, 'john', 70.2] abcd [786, 2.23] [2.23, 'john', 70.2] [123, 'john', 123, 'john'] ['abcd', 786, 2.23, 'john', 70.2, 123, 'john']

21 Không thể thay đổi một tuplefollow là không hợp lệ với tuple, vì chúng tôi đã cố gắng cập nhật một tuple, điều này không được phép. Trường hợp tương tự là có thể với danh sách: Tuple = ['ABCD', 786, 2.23, 'John',] list = ['ABCD', 786, 2.23, 'John',] tuple [2] = # cú pháp không hợp lệ với Tuple - Whatlist [2] = # cú pháp hợp lệ với danh sách Cannot change a tuple Following is invalid with tuple, because we attempted to update a tuple, which is not allowed. Similar case is possible with lists: tuple = [ 'abcd', 786 , 2.23, 'john', ] list = [ 'abcd', 786 , 2.23, 'john', ] tuple[2] = # Invalid syntax with tuple – WHAT list[2] = # Valid syntax with list

22 Từ điển-Từ điển của Tablepython là loại loại bảng băm. Chúng hoạt động giống như các mảng kết hợp hoặc băm được tìm thấy trong perl và bao gồm các cặp giá trị khóa. , mặt khác, có thể là bất kỳ đối tượng Python tùy ý nào. Dictionary – LOOK UP TABLE
Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object. Dictionaries are enclosed by curly braces [ { } ] and values can be assigned and accessed using square braces [ [] ].

23 Ví dụ: Dict = {} Dict ['One'] = "Đây là một" Dict [2] = "Đây là hai" Tinydict = {'name': 'John', 'Code': 6734, 'Dept' : 'SALES'} In dict # In tất cả các giá trị For example: dict = {} dict['one'] = "This is one"
dict[2] = "This is two" tinydict = {'name': 'john','code':6734, 'dept': 'sales'} print dict['one'] # Prints value for 'one' key print dict[2] # Prints value for 2 key print tinydict # Prints complete dictionary print tinydict.keys[] # Prints all the keys print tinydict.values[] # Prints all the values

24 đầu ra Đây là một trong số này là hai {'dept': 'sales', 'mã': 6734, 'tên': 'john'} ['dept', 'code', 'name'] ['sales', 6734 , 'John'] Từ điển không có khái niệm về trật tự giữa các yếu tố. Không chính xác khi nói rằng các yếu tố là "không theo thứ tự"; Họ chỉ đơn giản là không có thứ tự. output This is one This is two
{'dept': 'sales', 'code': 6734, 'name': 'john'} ['dept', 'code', 'name'] ['sales', 6734, 'john‘] Dictionaries have no concept of order among elements. It is incorrect to say that the elements are "out of order"; they are simply unordered.

25 Chuyển đổi kiểu dữ liệu, bạn có thể cần thực hiện chuyển đổi giữa các loại tích hợp. Để chuyển đổi giữa các loại, bạn chỉ cần sử dụng tên loại làm hàm. Có một số hàm tích hợp để thực hiện chuyển đổi từ loại dữ liệu này sang loại dữ liệu khác. Các chức năng này trả về một đối tượng mới đại diện cho giá trị được chuyển đổi. Data Type Conversion Sometimes, you may need to perform conversions between the built-in types. To convert between types, you simply use the type name as a function. There are several built-in functions to perform conversion from one data type to another. These functions return a new object representing the converted value.

26 int longx = int ["100", 2] #converts x thành một số nguyên. Cơ sở chỉ định cơ sở nếu x là chuỗi.print xprint loại [x] x = long ["100", 10] #converts x thành một số nguyên dài. Cơ sở chỉ định cơ sở nếu x là một chuỗi. Int long x = int["100" ,2] #Converts x to an integer. base specifies the base if x is a string. print x print type[x] x = long["100" ,10 ] #Converts x to a long integer. base specifies the base if x is a string.

27 đầu ra int long4100 Output Int long 4 100

28 float, float in phức tạp ["-32.54e100"] in phao in ["-32.54e-100"]#chuyển đổi X thành số điểm nổi. Phức tạp [2, 3]#tạo ra một số phức. Float, Complex print float["-32.54e100"] print float["-32.54E-100"]
#Converts x to a floating-point number. print complex[2 ,3] #Creates a complex number.

29 đầu ra-3.254E+101-3.254E-997.2E+12 [2+3J] output -3.254e+101 -3.254e-99 7.2e+12 [2+3j]

30 str x = 9 in x loại in [x] x = str [x] #converts đối tượng x thành một biểu diễn chuỗi.9 str x = 9 print x print type[x] x = str[x]
#Converts object x to a string representation. 9

31 repr-[đến một chuỗi] x = [1,2,3] in x loại in [x] y = repr [x] in yprint loại [y] in y [0] in y [-1] #converts đối tượng x đến một chuỗi biểu thức. Repr – [to a string] x = [1,2,3] print x print type[x] y = repr[x]
print y print type[y] print y[0] print y[-1] #Converts object x to an expression string.

32 đầu ra [1, 2, 3] [] output [1, 2, 3] [ ]

33 EVAL X = EVAL ["1+2"] In x Loại in [x] #EvalUates một chuỗi và trả về một đối tượng.3 Điều này sẽ đánh giá một chuỗi như thể đó là mã python. eval x = eval["1+2"] print x print type[x]
#Evaluates a string and returns an object. 3 This will evaluate a string as if it were Python code.

34 tupleprint tuple ["123"]#chuyển đổi s thành một tuple. ['1', '2', '3']] tuple print tuple["123"] #Converts s to a tuple. ['1', '2', '3']

Danh sách 35 listPrint ["123"]#Chuyển đổi s thành danh sách. ['1', '2', '3']]] list print list["123"] #Converts s to a list. ['1', '2', '3']

36 SetPrint Set ["123"]#Chuyển đổi s thành set.set [['1', '3', '2']]] set print set["123"] #Converts s to a set. set[['1', '3', '2']]

37 Dict In Dict [SAPE = 4139, Guido = 4127, Jack = 4098] #Creates a Dictionary. D phải là một chuỗi của các bộ dữ liệu [khóa, giá trị]. {'sape': 4139, 'jack': 4098, 'guido': 4127} dict print dict[sape=4139, guido=4127, jack=4098]
#Creates a dictionary. d must be a sequence of [key,value] tuples. {'sape': 4139, 'jack': 4098, 'guido': 4127}

38 người khác Frozenset [s] #converts S thành một bộ đóng băng. chr [x] #converts một số nguyên cho một ký tự.unichr [x] #converts một số nguyên vào ký tự unicode.ord [x] #converts một ký tự duy nhất vào giá trị số nguyên của nó.hex [x] #converts String.Oct [x] #converts một số nguyên cho chuỗi octal. others frozenset[s] #Converts s to a frozen set. chr[x]
#Converts an integer to a character. unichr[x] #Converts an integer to a Unicode character. ord[x] #Converts a single character to its integer value. hex[x] #Converts an integer to a hexadecimal string. oct[x] #Converts an integer to an octal string.

39

Một biến trong Python là gì?

Biến Python là một tên biểu tượng là một tham chiếu hoặc con trỏ đến một đối tượng.Khi một đối tượng được gán cho một biến, bạn có thể tham khảo đối tượng bằng tên đó.a symbolic name that is a reference or pointer to an object. Once an object is assigned to a variable, you can refer to the object by that name.

Biến là gì và các loại của nó trong Python là gì?

Một biến không có gì ngoài một yếu tố lập trình được sử dụng để xác định, lưu trữ và thực hiện các hoạt động trên dữ liệu đầu vào.Các biến Python có bốn loại khác nhau: số nguyên, số nguyên dài, float và chuỗi.Integer, Long Integer, Float, and String.

Các biến Python với ví dụ là gì?

Khóa học miễn phí: Lập trình với Python..
Một tên biến phải bắt đầu bằng chữ cái của bảng chữ cái hoặc dấu gạch dưới [_] Ví dụ: ABC = 100 #valid Cú pháp.....
Nhân vật đầu tiên có thể được theo sau bởi các chữ cái, số hoặc gạch dưới.....
Tên biến Python là trường hợp nhạy cảm.....
Các từ dành riêng không thể được sử dụng làm tên biến ..

3 loại biến trong Python là gì?

Số Python..
int [số nguyên đã ký].
Float [điểm nổi giá trị thực].
phức tạp [số phức].

Bài Viết Liên Quan

Chủ Đề