This article mainly introduces the list and bitwise operators in Python. it is the basic knowledge in getting started with Python. For more information, see
Python list
List is the most frequently used data type in Python.
The list can implement the data structure of most Collection classes. It supports characters, numbers, strings, and even lists (so-called nesting ).
The list is identified. Is the most common composite data type in python. You can see this code.
The variable [header subscript: tail subscript] can also be used to split the list. the corresponding list can be truncated, starting from left to right Index with 0 by default, from right to left, the index starts from-1 by default. the subscript can be null to indicate that the header or tail is obtained.
The plus sign (+) is a list join operator, and the asterisk (*) is a repeated operation. Example:
#! /Usr/bin/python #-*-coding: UTF-8-*-list = ['abcd', 786, 2.23, 'John', 70.2] tinylist = [123, 'John'] print list # print list of output complete list [0] # print list [] # print list of elements from the second to the third output [2 :] # print tinylist * 2 # print list + tinylist # print the combined list twice
Output result of the above instance:
['abcd', 786, 2.23, 'john', 70.2]abcd[786, 2.23][2.23, 'john', 70.2][123, 'john', 123, 'john']['abcd', 786, 2.23, 'john', 70.2, 123, 'john']
Python bit operators
Bitwise operators regard numbers as binary values for calculation. The bitwise algorithm in Python is as follows:
The following example demonstrates the operations of all bitwise operators in Python:
#!/usr/bin/pythona = 60 # 60 = 0011 1100 b = 13 # 13 = 0000 1101 c = 0c = a & b; # 12 = 0000 1100print "Line 1 - Value of c is ", cc = a | b; # 61 = 0011 1101 print "Line 2 - Value of c is ", cc = a ^ b; # 49 = 0011 0001print "Line 3 - Value of c is ", cc = ~a; # -61 = 1100 0011print "Line 4 - Value of c is ", cc = a << 2; # 240 = 1111 0000print "Line 5 - Value of c is ", cc = a >> 2; # 15 = 0000 1111print "Line 6 - Value of c is ", c
Output result of the above instance:
Line 1 - Value of c is 12Line 2 - Value of c is 61Line 3 - Value of c is 49Line 4 - Value of c is -61Line 5 - Value of c is 240Line 6 - Value of c is 15