3.Python the basics of what type of variable it

1.Python what type of data? ?

There are five standard Python data types:

  • Numbers (Digital)
  • String (String)
  • List (list) symbol []
  • Tuple (tuple) symbol () ---- tuple not secondary assignment corresponding to read-only list.
  • Dictionary (dictionary) corresponding to the key hash values ​​among java

2.Python digital

Python supports four different types of numbers:

  • int (signed integer)
  • long (long integer [may also represent octal and hexadecimal])
  • float (float)
  • complex (plural)

3.Python string

Strings or string (String) is a string of characters consisting of numbers, letters, the underscore.

List of strings python are two kinds of values ​​in this order:

  • The default start index 0 from left to right, the maximum range is a little string length
  • Index of default from right to left at -1, the maximum range is the beginning of a string

If you want to achieve access to the sub-section from a string, it may be used [superscript head: Tail index]  to intercept the corresponding string, where the subscript 0 is counted from the beginning, can be positive or negative, the represent landmarks may take empty head or tail. 

[The header: Tail index]  substring of characters acquired target comprising the head, but not the end of the target character.

The following example:

str = 'Hello World!'  

Print STR [ 2 : . 5 ] String # output string between the third to sixth

4.Python list

List with  [] identified python is the most common complex data type.

And a list of strings can also be taken as

Cutting the value list may be used in variable  [head index: Tail index], the corresponding list will be taken, beginning from left to right index 0 by default, default indexes from right to left at -1, the subscript may be empty means taking the head or tail.

Plus  + is the concatenation operator list, the asterisk  * is repeated.

5.Python tuple

Tuple is another data type, similar List (list).

A tuple  identifier (). Internal element separated by commas. But not the second tuple assignment, equivalent to the read-only list.

6.Python dictionary

Dictionary (dictionary) python is in addition to being outside the list of the most flexible type of built-in data structures. List is an ordered collection of objects, dictionaries are unordered collections of objects.

The difference between the two is that: among the elements of the dictionary is by the access key , rather than by shifting access.

Dictionaries with "{}" logo. A dictionary index (key) value and a value corresponding to its composition.

如  dict = {'name': 'john','code':6734, 'dept': 'sales'}

7. Data type conversion

Data types will involve the issue of some data type conversion

 

 

 

Guess you like

Origin www.cnblogs.com/zluckiy/p/11627629.html