Python learns the -5.python of variables and data types and the segmentation and connection of strings

Source: Internet
Author: User

In Python, the variable type is fixed and cannot be modified once it is declared (in Python it should not be declared, but should be used)

That's right:

1 var = 12print(Var)3 var = 24print(VAR)

Output variable var values, 1 and 2 in turn.

Error:

1 var = 12print(Var)3" I am a variable "4  Print(VAR)

Compile errors, error on the third line.

Data types in Python:

Boolean Isclosed=true
Integer Age=18
Float height=1.70
String message= "Hello World" or message= ' Hello World '
List list=[1,2,3,4,5]
Tuple Tuple= (1,2,3,4,5)
Dict dict={' Tom ': ' Lily ': 20}
Set Set=set ([1,2,3,4,5])

Note: A tuple is a simplified list that cannot be modified once it is initialized. Set is a collection, and elements cannot be duplicated.

A string in Python.

Declaring a string in Python can be in single or double quotes:

1 ' Hello ' 2 " Hello " 3 Print (VAR==VAR2)

The output is true.

Segmentation of Strings:

1 ' I am tom\n, and you? ' 2 words = var.split ()3print(words)

The output will be

['I'am'Tom', and'you? ' ']

Python By default splits strings by spaces and line breaks

The connection of the string:

1 words = ['I','am','Tom'  ]2". Join (words)3print(str)

The output:

I am Tom

Python learns the -5.python of variables and data types and the segmentation and connection of strings

Related Article

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.