Python beginner's first day study notes-the first ptyhon program and python variable, pythonptyhon

Source: Internet
Author: User

Python beginner's first day study notes-the first ptyhon program and python variable, pythonptyhon
1. python comments and the first python program:

1. Single line comment

# Author Xiajq

2. Multi-line comment

'''

------------ Comment content ---------------------------

'''

3. character encoding (not required for Versions later than python3.5. Utf8 is used by default)

-*-Coding: utf8 -*-

4. Run the command in a python File

#! /Usr/bin/python

5. The first python Program

#! /Usr/bin/ptyhon

#-*-Coding: utf8 -*-

# Author: XiaJinQi

Print ("hello wolrd ")

Ii. python variables:

1. python variables must consist of letters, underscores, and numbers. And cannot start with a number.

Name = "xiajinqi"

Print ("my name is {name}". format (name = name ))

Print ("my name is", name)

 

3. Format and output of strings.

Enter the user's basic information: name, age, job, and salary. And formatted and printed.

------------------------------------- Info of xiajiqni ----------------------------------
Name: xiajiqni
Age: 100
Salary: 33000.
Job: IT

1. Method 1:

Name = input ("name :")

Age = input ("age ")

Salary = input ("salary ")

Job = input ("job ")

Info = '''

---------------------------------------------------------------- Info of % s ---------------------------------------------------

Name: % s

Age: % s

Salary: % s

Job: % s

''' % (Name, name, age, salary, job)

Print (info)

2. method 2

Name = input ("name :")

Age = input ("age :")

Salary = input ("salary :")

Job = input ("job :")

Info = '''

---------------------------------------------------------------- Info of {name }---------------------------------------------------

Name: {name}

Age: {age}

Salary: {salary}

Job: {job}

'''. Format (name = name, age = age, salary = salary, job = job)

Print (info)

 

3. Method 3

 

Name = input ("name :")

Age = input ("age :")

Salary = input ("salary :")

Job = input ("job :")

Info = '''

---------------------------------------------------------------- Info of {0 }---------------------------------------------------

Name: {1}

Age: {2}

Salary: {3}

Job: {4}

'''. Format (name, age, salary, job)

Print (info)

 

4. String concatenation (not recommended)

Print ("age" + "100 ")

 

 

 

 

 

 

 

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.