Python first day

Source: Internet
Author: User

The 3.0 version of Python3   python, often referred to as python 3000, or simply py3k. This is a large upgrade relative to earlier versions of Python. In order not to carry too much burden, python 3.0 in the design of the time did not consider backwards compatibility.    First python3.x program   #!/usr/bin/python3  print ("hello, world!")      Execute command:python hello.py   output results:hello, world!  python3  Variables in the base data type        python do not need to be declared. Each variable must be assigned before it is used, and the variable will not be created until the variable is assigned.      in Python, a variable is a variable, it has no type, and what we call "type" is the type of object in memory that the variable refers to. There are six standard data types in     python 3:     numbers (digital)      String (String)     list (list)     tuple (tuple)     sets (collection)     dictionaries (dictionary) Numbers (digital)     python 3 supports int, float, bool, Complex (plural).      the assignment and calculation of numeric types is straightforward, just like most languages. The built-in type () function can be used to query the object type that the variable refers to.     string (String)     python in string str with single quotation mark ('   ') or doubleEnclose the quotation marks (" ") and use a backslash (\) to escape the special characters.     list (list)     list (list)   is the most frequently used data type in  Python . The      list is a comma-delimited list of elements written between square brackets. The types of elements in the list can be different     Python  conditional control the general form of the IF statement in the if  statement     python is as follows:         if condition_1:             statement_block_1        elif  condition_2:            statement_block_2         else:             statement_block_3                  if   "condition_1"   for  True  will execute   "Statement_block_1"   block statement, if   " Condition_1 "  for Fa    lse, will judge  " ConditiOn_2 "If" condition_2 "  for  True  will execute  " statement_block_2 "  block language      sentence, if   "Condition_2"   false, the "STATEMENT_BLOCK_3" block statement is executed.      Example:    if username == user:         print ("Right name") &NBSP;&NBSP;&NBSP;&NBSP;IF&NBSP;PASSWORD&NBSP;==&NBSP;PASSWD:         print ("Welcome to login")      Else:        print ("Password error")     else:         print  ("Username error")          while  Loops      The following instances use  while  to calculate  1  to   The sum of the 100 :        #!/usr/bin/env python3      n = 100     sum = 0    counter = 1    while counter <= n:         sum = sum + counter         counter += 1     print ("Sum of 1  until %d: %d " %  (n,sum))

Execution Result: Sum of 1 until 100:5,000



The For statement Python for Loop can traverse any sequence of items, such as a list or a string. The general format for the For loop is as follows: for <variable> in <sequence>: <statements> Else: <statemen Ts>

Python first day

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.