Python Introductory article

Source: Internet
Author: User
Tags for in range set set

Python is very hot, this year's study plan also has to learn python, this year's goal is to be able to use Python to do simple operation, can write simple crawler, strategy, can achieve this goal.

Because the goal is to write something first, so I do not need to understand Python particularly deep, follow the great god Liaoche Blog to learn python, while doing their own summary.

Data:

List

The list is similar to the C-language array, except that it can be nested and provides various interfaces.

 #  !/usr/bin/python  classmates  =["  hello   ", "   Zhang   ", "   Jingle   ", "   feiailing   " ]   Print   Classmatesclassmates.insert ( 1,  "  jingledddddd   "  )  print  classmates 


1. Example classmates=[' 1 ', ' 2 ', ' 3 ']

2, support subscript access classmates[0], assignment or printing can be

3. Interface:

List number: Len (classmates) = 3 len (classmates[1]) = 1, first refers to the number of elements, and the second refers to the length of a string

Insert Classmates.insert (1, ' zhangjingle '), the first element refers to the subscript, the second is the value

Delete: Classmates.pop () classmates.pop (i)

Visit: classmates[0] classmates[1] clssmates[2], classmates[-1] classmates[-2],classmates[-3]

Tuple: Structure:
There are two main points:

1, after initialization can not be modified

2, when there is only one element need to add,

t = (' 1 ', ' 2 ')

t = (1,): is a tuple data type with only one element

t = (): parentheses

t= (1): 1

Condition Judgment:

if   xx:  print   xxxxxxelif  xxxxx:  print  aaaaa Else : Print XCCCCCCC

For loop:

sum = 0 for in range (101):    = sum + xprint sum

While loop:

Note that there are colons: and Indentation, others are very simple

Data input:

Proper input 100 is an error, because the input is a string, if you want to judge with integers, you need to do a conversion.

Dict:

Similar to the map in C + +, set is a collection without duplicates.

d = {‘Michael‘: 95, ‘Bob‘: 75, ‘Tracy‘: 85}

To create a set, you need to provide a list as the input collection:

set([1, 2, 3])

Set has add and Rmove two method operations, there is a & operation between the set set and the set.

Function:

Define with Def,: Split, indent representation function body

def myprint ():     Print " maindddddd " Myprint ()

Python Introductory article

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.