Common data types in Python

♥️Author : Xiao Liu at Station C

♥️Personal homepage: Xiao Liu's homepage

♥️ Share cloud computing network operation and maintenance classroom notes every day, hard work may not necessarily pay off, but there will be gains, come on! Work hard together for a better life!

♥️Under the setting sun, it is the most beautiful bloom, the tree is thousands of feet tall, and the fallen leaves return to the roots. Life is not easy, and the true love in the world

Table of contents

1. Python

2. Common data types

1. Integer type (int)

2. Floating point type (float)

3. Boolean type (bool)

4. String type (str)

3. Type conversion

1. Conversion rules

4. Overall example

 analyze


1. Python

Python was designed by Guido van Rossum of the Netherlands Research Society for Mathematics and Computer Science in the early 1990s as an alternative to a language called ABC . [1] Python provides efficient high-level data structures and simple and effective object-oriented programming. Python's syntax and dynamic typing, as well as its interpreted nature, make it a programming language for scripting and rapid application development on most platforms, 

2. Common data types

1. Integer type (int)

Examples of integer types: 111, 222, 333, 444

2. Floating point type (float)

Examples of floating point types: 1.2, 3.2, 43.2, 432, 55

3. Boolean type (bool)

There are only two Boolean types: TRUE (yes) FALSE (no)

4. String type (str)

There are three types of strings: single quotes, double quotes, triple quotes

Example: 'I am a single quote' "I am a double quote" '''I am a triple quote'''

3. Type conversion

When connecting str type with int type, error solution, type conversion

1. Conversion rules

str() Function: Convert other data types into strings. Note: You can also use quotation marks to convert,

举例
str()
    ‘123’

int () function: convert other data types into integers. Notes: 1. Text type and decimal strings cannot be converted into integers. 2. Floating point numbers are converted into integers, and rounded up.

举例
int(‘123
    int(9.8)

float() function: convert other data types to floating-point numbers. Note: 1. Text cannot be converted into integers. 2. Integers can be converted into floating-point numbers with 0 at the end.

举例
float('9.9')
float(9)

4. Overall example

si='128'
f1=98.7
s2='76.77'
ff=true
s3='hello'
print(type(s1),type(f1),type(s2),type(ff),pyte(s3))
print(int(s1),type(int(s1)))
print(int (f1),type(int(f1)))
print(int(ff)),type(int(int(ff)))

 analyze

#Convert the int type to the str type through the str() function

#Convert str to int type, the string is a numeric string

#float is converted to int type, the integer part is intercepted, and the decimal part is discarded

#Convert str to int type, report an error, because the string is a decimal string

#When converting str to int type, the string must be a numeric string (integer), non-numeric strings are not allowed to convert

♥️Following is the driving force for my creation

♥️Like, is the greatest recognition for me

♥️This is Xiaoliu, I am inspiring to do every article well, thank you everyone

Guess you like

Origin blog.csdn.net/lzl10211345/article/details/129129919