Novice Python first day of study notes-first Ptyhon program and Python variables

Source: Internet
Author: User

One, the Python comment and the first Python program:

1. Single-line Comment

# Author XIAJQ

2, multi-line Comment

‘‘‘

------------Comment Content---------------------------

‘‘‘

3, character encoding (python3.5 later version does not need to be set.) Use UTF8 by default)

-*-Coding:utf8-*-

4. Execute in Python file

#!/usr/bin/python

5. The first Python program

#!/usr/bin/ptyhon

# -*-Coding:utf8-*-

#Author: Xiajinqi

Print ("Hello wolrd")

Two, Python variables:

1, the Python variable must be a letter, underscore, the number composition. And start not a bit number.

Name = "Xiajinqi"

Print ("My name is {name}". Format (name =name))

Print ("My name is", name)

Three, the format of the string output of three ways.

Enter the user's basic information: name, age, job, salary. and format printing.

-------------------------------------Info of Xiajiqni----------------------------------
Name:xiajiqni
age:100
salary:33000
Job:it

1. Method One:

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, Mode two

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, Mode three

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")

Novice Python first day of study notes-first Ptyhon program and Python variables

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.