One hour Python per day (10.09)

Source: Internet
Author: User

Today is the first day to learn python.

To install Python:

It's easy to install Python. Download the python2.7 version on the https://www.python.org/website and install it directly, all the way to next. The default installation path for Python is under the C:python27 folder.

Say less nonsense:

Python's first HelloWorld application:

  print'helloworld! '

How Python directly outputs output variables will also output

' Hello world!! '>>>name

This will also output the Hello world!! However, the output from the print statement is not exactly the same as the print output: helloworld!! But the latter output is: ' Hello world!! '. The difference is because print calls the STR () function to display the object, and the variable is the call to the REPR () function to display the object.

Now note the PRINT statement:

Print ' %d is  a number and%s is a string' % (1,'1')

This is how Python formats the output string.

It's the same as the programming language we know.%d represents an integer,%s represents a string, and%f represents a floating-point type.

Application of the ' >> ' symbol in the Python print statement:>> used to redirect output

LogFile = open ('e:/python/hellowrold.py','a')  Print >> logfile,'some text'logfile.close ()

The text of the some text can be added to the helloworld.py file in the Python folder under the E: Disk. Where >> is used to redirect output.

Python's raw_input function: He reads the standard input and saves the read input to the specified variable.

Username = raw_input ('Enter your name:')

Executing such a statement will require the user to enter and save the input in username.

If you want to convert the input to int, you can use the Int () function.

One hour Python per day (10.09)

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.