Python Basics: Hello World, annotations, variables, data types

Source: Internet
Author: User

  Since I've been in touch with the programming language, there are often three question marks in my mind:

    1. What is it?
    2. What's the use of this?
    3. How does this work?

I think beginners a thing, the three question marks all understand, then the rest is the right to the process of a clever, in the next blog, each knowledge point, I try to surround the three question marks to write

  

  First Python applet: Hello World

Then start the subject, first of all, the python inside the Hello World, do not spray do not spray, borrow a word from a king: the sense of ritual is very important! The first small program to get started in every language is Hello world, and there seems to be nothing wrong with that phrase [ cover your mouth ]

1 Print ("HelloWorld")

This is the Hello world in Python, Jane is not simple? Remote Memory beginner Java time, light a main () on a long, Nei noodles ah have wood

Print () is a built-in function in Python (or can be said to be a self-contained method?). Its role is to output the contents of the parentheses, for example, we want to use python output a word "I started blogging in the blog Park", the code is as follows:

1 Print (" I started blogging in the blog Park ")

Variables in Python

  Let's take a look at the variables in Python: variables are basically names that represent (or refer to) a value, for example, if you want the name Num to represent 3, the code is as follows:

1 num=3

Such an operation is called assignment, the value 3 is assigned to the variable num, and after the variable is assigned, the variable can be used in an expression, for example:

1 Print (num*2)

This code is translated in Chinese, output num multiplied by 2, where we used the variable num.

Variable naming rules

    1. Variable names can only be any combination of letters, numbers, or underscores
    2. The first character of a variable name cannot be a number
    3. Keyword cannot be declared as a variable name

      The keywords in Python have [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ' For ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' Return ', ' try ', ' while ', ' with ', ' yield ']

Comments in Python

The pound sign (#) is special in Python, and when entered in the code, everything on its right is ignored and will not be run

  

1 # This is a single-line comment, the bank content will not be interpreted to run 2 num=33print(num)

In Python, in addition to the use of # (single-line comment), there is "" "" "" "" or "" "or use single quotation marks '" ' Multi-line comment '

1 """I'm2 is a3 more4 Line5 Note6 Interpretation"""7 8Num=39 " "I alsoTen is a One more A Line - Note - Interpretation" " the Print(num)

You can run this code in the compiler, there is not much to explain

Data types in Python

There are many different types of data in Python, and here we only say three common ones:

Number: Int (integral type), long (Long Integer), float (float), complex (plural),

Boolean value: True or FALSE, 1 or 0

String: is a string of characters .....

Three ways to define a string:

    

# single quote definition name1=' dragon '# double quotes definition name2=" Zhaohu "  # triple quote definition (can define multiple lines of string) as with annotations, you can use three double quotes or three single quotes name3= ' dynasty '   name4=" " " Mahan  " ""

Come here today, if there are errors or shortcomings, but also to the passing of the Daniel a lot of guidance

Python Basics: Hello World, annotations, variables, data types

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.