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 knowledge points of Python data type

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Today, Xiaobian will share with you what are the relevant knowledge points of Python data type knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone's reference, I hope you have gained something after reading this article, let's learn about it together.

I. Number type

1, integer int

It's integers: 100, 200, 2, 3, 4......................

2, floating point type float

Decimals: 1.22, 1.32, 1.00·····

3, Built-in function--type

type(variable name or variable that has been assigned)

count=100print(type(count))print(type(1.14))

1. What is a string:

(1) Everything you see in books is a string.

(2) String wrapped in ' ' or ''

(3) A character string can contain any character: letters, numbers, symbols, and there is no order

(4) In Python, str is used to represent string types, and strings can be defined through this function class:

safe = str ('will rely on ')name = ' Xiaoming 'message = ' yeah 'in = 'hao '

2. String built-in functions:

3. Important ideas of strings:

(1) String cannot be changed

4. Python built-in function id:

(1) Return the memory address of the variable

name = 'xiaohua'x=id(name)print(x)name='xiaoming'y=id(name)print(y)

So you can see why strings are immutable.

(2) Digital address =id(variable)

5. Python built-in len:

(1) Return the length of the string

(2) Cannot return the length of a numeric type

(3) Return value =len(string)

lenggth=len("w hen hao ")print(length)name = 'xiaohua'x=id(name)print(x)name='xiaoming'y=id(name)print(y)new_name=nameprint(id(new_name))info=''' It's too greasy. '''print(info)info1="ni"info2='ni'new_str= "hello world! 'yes'"print(new_str)new_str1= 'hello "world"! yes'print(new_str1)

6. String usage:

(1)Use of built-in member functions in

The member operator is used to determine whether the desired member exists in your data

(2)Built-in function max

Returns the largest member of the data

(3)Built-in function min

Returns the smallest member of the data

(4)accumulation of strings

It's actually a concatenation of strings, using the symbol "+."

# coding : utf-8 str1='I love python'flag1='like' in str1flag2='python' not in str1print(flag1)print(flag2)str2='weather'str3='nice'print(str2+str3) 3. Boolean type

1. What is Boolean type, fixed value of Boolean type

True and false are Boolean types.

Fixed values: True,False

2. Use scenarios for Boolean types

Scene to judge true and false

3. Use of Boolean Functions

bool stands for Boolean type, and can also judge whether the result is true or false

4. Number, string application on Boolean type (built-in function bool)

0->False

Not 0->True

0.0->False

Not 0.0->True

str''->False

Non-empty string->True

IV. Empty type

1. Empty Type None

Does not belong to any data type is null type

2. fixed value

None.

Empty type belongs to False

V. List types

1. What is a list?

A list is a queue.

It's a collection of data types, and it's a data structure.

A list is an ordered, repeatable collection type.

2. Definition of lists

Use list to represent this type of list, and you can also use it to define lists

The elements in the list exist in a []

A list is a data structure of unlimited length, but don't create super-large lists.

3. Types in the list

string type

integer

floating-point

bool type

empty type

List type (nested)

4. Use of in, max, min in lists

1 in [1,2,3,4] =>true

max([1,2,3,4]) =>4

min([1,2,3,4])=>1

Max and min are used in lists, and elements in lists cannot be of multiple types.

# coding : utf-8 li=list[None,None,None]li1=[1,2,3]print(li)print(li1)max_list=[1,2,3,4]print(max(max_list))print(min(max_list))li2=[1,2,'jiafa','we','Ture']print(li2) VI, tuple type

1. What is a tuple?

Like a list, it is a queue that can store multiple data structures.

A tuple is also an ordered, repeatable set of elements.

2. Definition of tuples

tuple represents the type of tuple and can also be used to define a tuple

The elements of a tuple exist in a () parenthesis.

If there is only one member, follow it with a comma.

Difference Between Tuples and Lists

Tuples occupy less resources than lists

List mutable, tuple immutable

Type in tuple

integer

floating point

string

list

bool type

None type

Tuple type (nested)

in, max, min Use in tuples

Same as the list.

#coding utf-8tuple_test =('xiao ming',)#comma after an element print(tuple_test)print(type(tuple_test))

1. What is a dictionary?

A dictionary is a data type consisting of multiple keys and their corresponding values.

2. Dictionary structure and creation method

dict stands for dictionary and can create a dictionary

Save key and value in dictionary by {}

3. Data types supported by dictionaries

key supports string, numeric, and tuple types, but lists are unsupported.

value supports all Python data types

4. Dictionaries in lists and tuples

_list=[{1:1,2:3},{'one':1,'two':2}]

_tuple({1:2},{'one':1})

In Python 3.7 and previous versions dictionaries were unordered

5. Important features in dictionaries

The dictionary key is unique.

The above is all the content of this article "What are the knowledge points of Python data types?" Thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to 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.

Share To

Development

Wechat

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

12
Report