Python Learning Note Chapter 2 Basics

Source: Internet
Author: User

Program input

>>> print ('%s is number%d '% (' Python ', 1))
Python is number 1

Problem with output redirection (pending)

Text input
>>> user = input (' Enter login ' name: ')
Enter Login Name:root
>>> print (' Your login is: ', user)
Your Login Is:root

numeric string input
>>> num = input (' Now enter a number: ')
Now enter a number:22
>>> print (' Doubling your number:%d '% (int (num) *))
Doubling your number:44

While loop
>>> num = 0
>>> while num < 3:
Print (' Loop #%d '% (num))
Num +=1


Loop #0
Loop #1
Loop #2


For loop
>>> for item in [1,2,3,4,5]:
Print (item, end= ') # end indicates how print ends and defaults to end= "\ n" (newline)


12345

Python Learning Note Chapter 2 Basics

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.