Basic python syntax and python syntax

Source: Internet
Author: User

Basic python syntax and python syntax

I. Data Types

Python variables do not need to be declared. You can directly assign values to various types of data.

Name = 'zhang san'
Age = 20
Num = 12.5
Print (name, age, num)

Zhang San 20 12.5

II. if judgment

Num = int (input ('num: ') # type conversion
If num = 10: # if condition:
Print ('OK') # subcode indent
Elif num> 10:
Print ('Big ')
Else:
Print ('small ')

3. Loop

Count = 0 while True: # True is the loop condition print (count) # indent count + = 1
For I in range (, 2): # Start from 0, each running cycle, jump 2 numbers, print (I) until 10 # break else: # Run the else code block print ('no') if the loop exists ')

 

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.