First week of Python learning, first week of python

Source: Internet
Author: User

First week of Python learning, first week of python

  • I. My first program

 

print("Hello word!")

 

Therefore, python is a very concise language. Unlike c, c ++, and so on, you have to call a bunch of libraries to write a simple program. In addition, python 3 supports Chinese compiling.

 

 

  • Ii. Use of Variables

Python is a dynamic, strong language

name="fromzore"print(name)

 

You do not need to define the type of the variable. The system automatically defines the variable according to the input.

Name = "fromzore" age = input ("age"); pt2 = "% s your age is % s" % (name, age) print (pt2)

In input, the str type is input by default. To use % d, force conversion is required.

Name = "fromzore" age = int (input ("age") pt2 = "% s your age is % d" % (name, age) print (pt2)

No error is reported.

  • 3. Loop

The loop is divided into a while loop and a for loop. The difference between the loop and c is that python can be followed by else statements.

age=18sum=0while sum<3:   count= int(input("age"))   sum+=1   if sum==count:       print("you are right")       break   elif age<count:       print("It is biger than age")   elif age>count:       print("It is smaller than age")else:    print("Multiple input errors")

The result is as follows:

For Loop

for i in range(3):   count= int(input("age"))   sum+=1   if sum==count:       print("you are right")       break   elif age<count:       print("It is biger than age")   elif age>count:       print("It is smaller than age")else:    print("Multiple input errors")

Changing while to for results is the same.

Ps: there is an error in the first blog posting or where it is not well written. Please give me more advice.

 

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.