Stupid way to learn Python (1-10)

Source: Internet
Author: User

The following learning content is based on Python2

UTF-8

#conding: Utf-8 or #__coding: utf-8__

This sentence to be pinned, indicating that the code supports UTF8 format, it is best to add each code file


Comments

# A Comment, this was so you can read the your program later.

The code preceded by "#" is a comment, and the last line of each line of code is written with an explanatory message.


Python2 and Python3

Print "ABC" #python2的写法print ("abc") #python3的写法


Digital and mathematical calculations

+ Plus Plus

-Minus minus

/Slash Slash

* Asterisk asterisk

% percent percent percent

< Less-than, less than

> Greater-than greater than sign

<= less-than-equal less than equals sign

>= greater-than-equal greater than equals sign


Variables and naming

>>> cars = 100>>> print "There is", cars, "cars available."

Results: There is the available of cars.


More variables and printing

>>> my_name = ' Kavin ' >>> print "Let's talk about%s."% My_name

Results

>>> let's talk about Kavin.

%r and%s in Python

%r processing objects with the Rper () method

%s processing an object with the Str () method

In some cases, the result of both processing is the same, for example, to deal with an int type Object

%r will be more "on the side of the string."


String (srring) and text

W = "This is the left side of ..." E = "a string with a right side." Print W + ethis is the left side of...a string with a right Side.print "." * 10 .....


Print

days =  "Mon tue wed thu fri sat sun"  months =  "Jan\nfeb \nmar\napr\nmay\njun\njul\naug " print " here are the days:  ", days  print  "here are the months: ", months print  "" " There ' s  Something going on here. with the three double-quotes. we ' Ll be  able to type as much as we like. even 4 lines if  we want, or 5, or 6.  "" "$ python ex9.py here are  The days: mon tue wed thu fri sat sun here are the  months: jan feb mar apr mayjun jul aug there ' s something  going on here. with the three double-quotes. we ' ll be able  to type as much as we like. even 4 lines if we want, or 5,  Or 6.

\ n Force line break

Print "" "" "is displayed in the given format

"" can also use single quotation marks

Print "", ABC plus comma, no line break after comma


What is that

\ escape character to put hard-to-print characters into a string

\ r \ n are both escape characters, spaces are simple spaces, input spaces can be entered

\ t means to jump horizontally to the next tab position

\ r means enter.

It means a carriage return and a newline.







Stupid way to learn Python (1-10)

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.