[1]), (2, seq[2]), ... | | Methods defined here: | | __getattribute__ (...) | x.__getattribute__ (' name ')
Methods of traversing sequences
?
1 2 3 4 5 6 7
>>> list = [' A ', ' B ', ' C '] >>> for index, value in enumerate (list): Print index, value 0 a 1 B 2 c >> ;>
Six, using the Python random module's sample function randomly select a group of elements from the list
initial value of sum = 0 # Sets the initial value of a total number to store the calculated result of the total number while count 3. All the even numbers in the output 1-100For I in Range (1,101): If I% 2 = = 0: print (i)4. All the odd numbers in the output 1-100For I in Range (1,101): If I% 2! = 0: print (i)5, to seek the 1-2+3-4+5-6...99 of all the number andMethod One:Count = 1sum = 0while Count Method Two:sum = 0for i in range (1,100): if I% 2 = = 0: sum = s
Python sequence type, python Sequence
In python,Sequence typeIncludingString(Common string and unicode string ),ListAndTuplesThe so-called sequence, that is, the sequential arrangement of members, can be accessed by subscript. Assume that there are n elements in the sequence. when accessing a single element, the subscript starts from 0 and ends with n-1. If it is
Built-in functions learned by the python tribe, python tribe
Recently, I joined the python tribe. I felt that it was very interesting. I had a bit of fun. I learned a lot of built-in functions that I didn't know before, and I felt that I was about to remember them. So I started to display them.
1. divmod (a, B): Take the quotient and remainder of a divided by B,
Python traverses the serial number and value in the list (three methods), python serial number
Three methods are used to traverse the serial numbers and values in the list:
I recently learned the python language and felt that it has greatly improved my work efficiency. I wrote this blog on Valentine's Day. I will not talk about it here, but I will post it direc
sleep #The third param means the Lock def loop(nloop,sec,lock): print "Thread ",nloop," start and will sleep ",sec; sleep(sec); print "Thread ",nloop," end ",sec; lock.release(); def main(): seconds=[4,2]; locks=[]; for i in range(len(seconds)) : lock=thread.allocate_lock(); lock.acquire(); locks.append(lock); print "main Thread begins:",ctime(); for i,lock in enumerate(locks): thread.start_new_thread(loop,(i,c
Python BASICS (12)-module, python basics-Module
URL: http://www.cnblogs.com/archimedes/p/python-modules.html.Module Introduction
If you exit the Python interpreter and re-enter, all previously created definitions (variables and functions) will be lost. Therefore, if you want to write a program that has been saved for a
interested in:
In-depth introduction to the use of parameters in Python functions and the traps of default parameters
Use Python built-in modules and functions to convert numbers in different hexadecimal formats
Usage Analysis of element traversal using the enumerate function in python
Exploring the use of open f
Python mutable and immutable objectsAll of the data in Python is built around objects, which can be divided into two categories: mutable objects and immutable objects. When a variable is assigned a value, the variable holds an object reference (which can be understood as a pointer in C), pointing to the area in memory where the object resides.For an immutable object, the object itself cannot be changed (or
Python writes, Python writes, writes Python, makes PythonI am a first-line it enterprise programmer, and now receive a variety of code to write business:
Write C language, C language, C language job generation, C language writing
Write C + +, Generation C + +, C + + job generation, C + + job writing
Write pyt
for the first time. 6 7 32 19 82 28 30 41 100 39 71 29 45 30 94 77 62 26 25 19 82 20 55 43 73 8>> for I in iter (getrand, 50): print I, # obtain the random number of all 1-100 values before 50 for the first time 9 10 22 54 14 25 60 65 16 80 61 5 48 61 2 30 90 98 70 10 55 45 23 72 87 39 70 3 84 8511 >>>
8. BaseException is the base class of all exceptions. Exception is only the base class of all exceptions without exit.
9. locals/globals/vars/dir:
[1] locals/globals is a simple local/Global Obje
20 43 73> for I in iter (getrand, 50): print I, # obtain a random number 22 54 14 25 60 65 16 80 61 5 48 61 2 30 90 70 10 55 45 23 72 87 39 70 3 84 85>>
8. BaseException is the base class of all exceptions. Exception is only the base class of all exceptions without exit.
9. locals/globals/vars/dir:
[1] locals/globals is a simple local/Global Object dict relative to the current scope;
[2] vars () = locals (), vars (obj) = obj. _ dict __
[3] No parameter, set (dir () = set (locals (). keys (); if
A simple method to implement the type checker in Python 3, python type
Example Function
To develop a type checker, we need a simple function to experiment with it. The euclidean algorithm is a perfect example:
def gcd(a, b): '''Return the greatest common divisor of a and b.''' a = abs(a) b = abs(b) if a
In the preceding example, parameters a, B, and return values are of the int type. The expected types
Python self-study day-Two day (2)-python-list-tuples-dictionary, python-
ListFormat: name = []Name = [name1, name2, name3, name4, name5]
# List operations
Name. index ("name1") # query the name of the specified value. count ("name1") # query the name of the total number of specified values. clear ("name") # clear the list name. reverse ("name") # reverse the List
Python function Programming Guide (4): generator details, python programming guide
4. generator)
4.1. Introduction to generators
First, be sure that the generator is an iterator. The generator has the next method and has the same behavior as the iterator, which means that the generator can also be used in a Python for loop. In addition, the special syntax support
[Learn python with me] Start from Python and start from python
In other words, the high-rise buildings on the ground will not climb before they go. This is especially true for me. No matter how you code first, please test first when the wings of me are hard.
1. How to Run python?
Download the
Write by nine days Yan Ling (jtianling) -- blog.csdn.net/vagrxie
Discuss newsgroups and documents
I implemented "onekeycodehighlighter"Some minor issues encountered in, you need to implement global shortcuts, but in fact QT does not provide support for global shortcuts, so QT can only be used through WIN32API, and I, it uses pyqt and python to call Win32 APIs. In fact, there is no difficulty.
Because of the popularity of
code snippet to create a dictionary to calculate the frequency of occurrences of the elements in the result. Until one day, I found that I could use collections.deque.
From collections import Counterfrom random import randrangeimport pprint mycounter = Counter () for I in range: RA Ndom_number = Randrange (Ten) Mycounter[random_number] + = 1 for i in range (10):
0 101 102 133 64 65 116 107 148 129 8
5. Dictionary derivation
An important sign of Pyth
passed in an iteratable sequence. We need to pass in a generator object for perfect implementation.
Note the following code:
The above j is the generator type, and the following j is the list type:
j = (i for i in range(10)) print j,type(j) print '*'*70 j = [i for i in range(10)] print j,type(j)
Result:
I hope this article will help you learn Python programming.
How to Use the iterator in python?
List =
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.