Python Foundation-day01

Source: Internet
Author: User

Day1 Learning Content

    1. hello World Program
    2. variable
    3. user input
    4. expression if ... else statement
    5. expression for Loop
    6. Break and continue 
    7. expression while loop
    8. formatted output

The first small procedure of international practice

HelloWorld Program for Python language

Print ("Hello World")

In the Python language, the end of the statement does not need to be added;

Second, the variable

Python is an explanatory strongly typed dynamic language, meaning that each variable is assigned to it, and the data type is automatically recorded inside the system because Python is a strongly typed language, so in the subsequent run, if the data type of the variable is not changed by casting the data type, The data type of the variable will remain unchanged.

such as name = Gino

In the above assignment code, the variable name is not declared data type but this is legal in Python, Python does not need to declare the data type of the variable as C/c++,java and other languages, and the system automatically records when assigning a value of name to Gino, that is, The system automatically assigns a data type to name based on the data type of the assignment, where the data type of name is string

third, user input, If...else, while loop, break, continue, for Loop

Input in Python is responsible for user input and is the base code for interacting with the user

 

Example: Small game guessing a person's age, up to three guesses, three times after exiting the program

Involves content while looping, if...else, break,

In Java if: else is in the format:

if (judging condition)

{code block}

Else

{code block}

Python uses indentation to represent the format of the statement, indent once, and demote the statement once

If judging condition:

Print ("XXX")

Elif Judging conditions:

Else

Note that Python is if,elif (equals else if), and else needs a colon at the end:

While   count < 3: #创建while循环 count<3 for expressions to meet this condition loop execution 
guess_age = Int (input ("Guess Age:"))#input语句获取的所有数据的类型都为字符型String
if Guess_age = = Age_of_gino:
print ("Yes, you Got it")
break #break为结束整个循环 continue to skip this cycle into the next loop
elif guess_age > Age_of_gino:
print ("Think bigger")
Else:
print ("Think smaller")
count = count + 1
print ("You ' ve guess it {count} time". Format (count=count))#{count} is the formatted output and the output is assigned in the. Fomat
Else: #while不满足条件时执行语句else
print ("You have tried too mant times ... fuck off")
 






















for loop
for I in Range (initial value, end value, step)
Print ("loop", I)
here in the FOR loop the default initial value is 0

If the statement
  for me in range (Ten)  
print (" loop ", i)
So the output is
loop 0
loop 1
loop 2
...
loop 8
loop 9
altogether 10 times

Four, formatted output
Input variable value
Name = input ("Name:")
age = Int (input ("Age:")) #integer
Print (Type (age) , type ( str))
Job = input ("Job:")
Salary = input ("Salary:")

To create a formatted output
Info2 = " '
--------info of {_name}-----
Name:{_name}
Age :{_age}
Job:{_job}
Salary:{_salary}
". Format (_name=name,
_age=age,
_job=job,
_salary=salary)

The output result is

--------Info of Gino-----
Name:gino
Age:12
Job:it
salary:2000

Python Foundation-day01

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.