Python programming-from getting started to practicing note _1

Source: Internet
Author: User
Tags integer division sublime text sublime text editor

Start

    • You can run Python directly from the terminal, execute the python command, or you can execute the command via a text editor (the text created must end with a. Py and the editor knows it is going to run the program with the Pyhon interpreter)
    • When running Python at the terminal, press "Ctrl+d" or execute command exit () to exit Python and return to the terminal window
    • It's best to use lowercase letters when naming in Python, and use underscores to represent spaces
    • Sublime text editor is recommended. : Https://www.sublimetext.com/3 to long-term use please purchase a license, it is not possible to use the version you are using the Internet search for the corresponding license, that is, the registration code. Then click "Help" in the menu bar of sublime text and enter
    • Mac uses sublime text, its menu bar at the top of the system, not the Sublime Text window interface (I am mac small white)
    • For more information on how to use sublime text, recommend https://www.cnblogs.com/figure9/p/sublime-text-complete-guide.html
    • Sublime Text usage tips: https://www.zhihu.com/question/24896283
    • Sublime text in
      • function--Blue  
variables and simple data types

variables
    • Multiple assignments to a variable, or multiple changes, Python always records only the latest value of the variable
    • Naming rules
      • can only contain numbers/letters/underscores, and cannot start with a number
      • Variable names cannot contain spaces
      • Keyword and function names cannot be used as variable names
      • Short and descriptive
      • Be cautious with lowercase i and capital letter O, easy to see wrong
    • Reference variable name error, can be viewed according to the prompt to see what errors, frequently encountered errors
      • Forgot to assign a value to a variable
      • Spelling errors
string
    • Single and double quotes can be used, corresponding to the line
    • Python has methods to process strings, format: variable name A. Method B ()
      • The period (.) after the variable name a. Let Python Execute method B on variable name A to specify the operation. Each method is followed by a pair of parentheses, because sometimes it takes some extra action

Name= "Ada"

 ##  title ()     first letter in uppercase # #

print (Name.title ()) ada   # #upper ()   Full Capital Display # # print (Name.upper ()) ada   # #lower ()   Full lowercase # # print (name.lower) ada
    • Use the plus sign to stitch strings, or you can stitch strings directly or join them as strings.
    • Use escape character in string, newline ' \ n ', tab ' \ t '
    • Remove whitespace from a string
      • Remove whitespace after a string-method. Rstrip ()
      • Remove whitespace before a string-method. Lstrip ()
      • Remove whitespace at both ends of a string-method. Strip ()
    • In Python2, you do not need to enclose the string in parentheses, or you can print
Digital
    • Integer operations: Plus (+), minus (-), multiplication (*), except (/), exponentiation (* *)
    • Support order operations, just as in the usual order of calculation: first multiplication, then add minus, parentheses are counted in parentheses first.
    • Whitespace does not affect calculation expressions
    • Floating-point calculation, the number of decimal digits contained in the result is indeterminate
    • function str () cast multiply string to avoid type error
    • In Python2, the result of integer division contains only the integer part, note that it is not rounded! To avoid this, it is important to ensure that at least one operand is a floating-point number
    • Python2, Integer division can be when floating point number
Comments
    • Comment with pound sign (#)
    • A single line is possible, and can be followed by code

Don't attempt to write flawless code, write code that works well, decide whether to improve it, or instead write new code.

Python programming-from getting started to practicing note _1

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.