Learn Python from scratch-Data Type string, python-Data Type

Source: Internet
Author: User

Learn Python from scratch-Data Type string, python-Data Type

I,PythonData Type in

· Integer, for example, 1-100

· Long integer, which is a relatively large integer. Python 2 contains long integers; Python 3 does not

· Floating point numbers such as 1.23 and 3E-2

· Boolean type False True

II,Number(Number)Three Types:

·IntInteger

2) FloatBy default, 17 decimal places are retained, and the length will be lost.

For example: 0.0000000000000000000000000000000001

Display: 1e-37 = 1*10 to the power of 37

3) Bool Boolean Type

For example:

Num01= 100

IfNum01> 10:

Print ("This ratio10Large")

Else:

Print ("This ratio10Small")

# "Big" means "True", "small" means "False ".

 

Save characters

Str01 ="Www.iLync.cn"

Print (str01)

Print (str01 [0: 4])

 

The following is a wavy line, indicating that it is not a word that actually exists.

How to obtain the data type of a variable?

Print (type (num01) s's

Type: obtains the Data type of a variable.

Determines whether a variable belongs to a certain data type.

Isinstance () function to determine whether an object is of a known type, similar to type ().

IfIsinstance (str01, (str )):

Print ("string ")

 

Extended content:

Example:

Str01 ="Abcdefghijklmn"

#Print second digit

Print (str01 [1])

Print (str01 [-len (str01) + 1])

#Print second to last

Print (str01 [-2])

Print (str01 [len (str01)-2])

#Print a range

Print (str01 [5: 10])

Print (str01 [2: 5])

 

#Reverse Order

Print (str01 [:-1])

 

#Print2Times

Print (str01 * 2)

 

#Print each character3Times

List01 = []

I = 0

WhileI <len (str01 ):

Print (str01 [I] * 3, end ="")

I + = 1

 

#Enter a number (for example10), Generate10Items100If the number is less than the value, the average value, the maximum value, and the minimum value are used.

ImportRandom

Num = int (input ("Enter a number:"))

I = 0; current_num = 0; sum = 0

List01 = []

 

WhileI <num:

Current_num = random. randint (0,100 );

Sum + = current_num

List01.append (current_num)

I + = 1

Print (list01)

Print ("Average:% D"% (Sum/num ))

Print ("Maximum:% D"% Max (list01 ))

Print ("Minimum:% D"% Min (list01 ))

 

#Input a number into uppercase letters

Num = input ("Enter a number:")

Tuple01 = ("Zero","Yi","II.","Parameter","Si","Wu","Lu","Bytes","Bytes","Bytes")

I = 0

WhileI <len (num ):

Print (tuple01 [int (num [I])], end ="")

I + = 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.