Python Foundation One

Source: Internet
Author: User

1.Python helloworld!

#!/usr/bin/env python
print "Hello World!!!"

2.Python Basic variable naming

Legal variables:

Name= ' Freeman '

Nameinfo = ' Freeman '

Illegal variable:

Name-info = ' Freeman '

@name = ' Freeman '

Summary: Variables cannot be named with special characters and operators as variables, and you can use the wrong division method for named variables such as Nameinfo

3.Python Judgment Statement

#!/usr/bin/env python
Print "Hello1"
If 1 > 10:
Print "Hello2"
If 2 = = 4:
Print "Hello3"
Print "Hello 4"

Grammar:

An If expression:

Code logic block

Elif expression:

Code logic block

Else

Code logic block

Summary: Because Python does not have a program close character, it is because it uses code indentation to express a piece of code or logic

3.Python Arithmetic expressions

= = equals

>= greater than or equal to

<= less than or equal to

4.Python Loop statement

#!/usr/bin/env python
While True:
Print "HH"
Target=false
While True:
Print "GG"
Target=true
Break
If Target:
Break

#!/usr/bin/env python
Import Random
Import tab
Suiji=random.randrange (4)

#num =raw_input (' Please number: ')
While True:
Num=raw_input (' Please number: ')
if int (num) = = Suiji:
print "OK"
Print Suiji
Break
Elif num > Suiji:
Print "Xiao Xiao Xiao"
Print Suiji
Continue
Elif Num < Suiji:
Print "Dadada"
Print Suiji
Continue

5.Python Basic data types

Several data types built into Python are: lists, tuples, dictionaries, strings, numbers, character points, etc.

6.Python Several modes of open file

R Read mode

W Write mode

A append mode

A + w+ r+

7.Python syntax sugar (IF true and ternary operator)

def is_freeman (name):
res = True if name.lower () = = "Freeman" Else False
return res
Print Is_freeman ("Freeman")
Print Is_freeman ("free")

#lambda
A = lambda x, y:x > Y
Print a (5,3)

8.Python use the above methods to practice

#!/usr/bin/env python
User=raw_input ("Please Name:")
For I in range (3):
Passwd=raw_input ("Please passwd:")
if user = = ' JZCLVN ' and passwd = = ' Redhat ':
Print "Wlecome"
Break
Else
print "Bye"
Else
Print "Lock User"

Python Foundation One

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.