Python Basics Quick Learn-hello.py

Source: Internet
Author: User
Tags arithmetic operators

1 #Coding=utf-82 3 #hello.py python learning start4 5 #====== Comment ======6 #Python uses the # notation to mark annotations7 8 #One comment9 Print 'Hello world!'Ten  One #====== operator ====== A #Arithmetic Operators - #self-Increment 1-decrement 1 operator not supported - #* * Indicates the highest priority of the exponentiation the Print-2*4 + 3**2 -  - #comparison operator returns a Boolean value (True/false) - Print2 < 4; + Print6.2 > 6.2001 -  + #A logical operator joins any expression together to return a Boolean value A Print3 < 4 and4 < 5 at Print  not6 <= 6.2 - Print2 > 4or2 < 4 -  - #====== variable ====== - #no need to pre-declare variable types -Count = 10 in Print "count is%d"%(count) -  to #====== string ====== + #define string single or double quotation marks (three quotation marks can be used to contain special characters) -Pystr ='Python' theIscool ='is cool!' * #String Connection $ PrintPystr +' '+IscoolPanax Notoginseng  - #index: [] Slice: [:] the #Index rule: The index of the first character is 0, the last character index is -1 + PrintPystr[0] A PrintPystr[2:5] the PrintIscool[:2] + PrintIscool[3:] - PrintIscool[-1] $  $ #====== list ====== - #list elements with [] package number and value can be changed - #operations like arrays can be indexed and sliced theAlist = [1, 2, 3, 4] - PrintalistWuyi PrintAlist[0] the  - #====== tuple ====== Wu #tuple elements with () package number and value can not be changed - #operations like arrays can be indexed and sliced AboutAtuple = ('Robots', 77, 93,'Try') $ PrintAtuple - PrintAtuple[:3] -  - #====== Dictionary ====== A #The mapping data type is composed of key-value (key-value) pairs + #The dictionary element is wrapped with {} theAdict = {'Host':'localhost'} - Printadict $adict['Port'] = 8080 the PrintAdict.keys () the Printadict['Host'] the  the #====== control Operation ====== - #keyword followed by expression ': ' End inx =-1 the ifX <. 0: the     Print '"X" must be atleast 0!' About  theCount =0; the  whileCount < 3: the     Print 'Loop #%d'%(count) +Count + = 1 -  theFoo ='ABC'Bayi  forCinchfoo: the     PrintC the  - #====== List parsing ====== -squared = [x**2 forXinchRange (4)] the  forIinchSquared: the     PrintI the  the #====== function ====== - #The definition function consists of the def keyword and its subsequent function name, plus the required function parameters ': ' End the #function parameters can define a default value the defaddme2me (x): the     'Apply + operation to argument'94     return(x +x) the  the PrintAddme2me (4.25)

Python Basics Quick Learn-hello.py

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.