Python notes (data type)

Source: Internet
Author: User
Tags numeric lowercase

Numeric type: integer (int), long Integer (length), floating-point number (float), plural (complex), no need to specify numeric types when defining variables, such as: A=1, a=12.5

Operators: In addition to subtraction and powers * *, Division/, divide//, remainder%, or |, Xor ^, and, left-shift operation <<, right shift operation >>.

String: String can be circled with single and double quotes, such as: A= ' 123456 is a number '

Escape character: \ n line break, \ t tab, \ r carriage return, \ \ = \,\ ' represents single quotes instead of string ends, \ ' represents double quotes.
For example:
A= ' I'm just a single quote instead of an end! I can still change the line! '
Print (a)
Run Result:
c:\>a.py
' I'm just a single quote, not an end!
I can also change lines!
If you need to output \ n, the code is \\n.

Action character (omitted a= ' ABCDE ') in the instance:
Capitalize ()--Capitalize the first letter: print (A.capitalize ()) to run the result to ABCDE
count ()--Get the number of a substring:p rint (A.count (' B ')) The result of the run is 1,b only once
find ()--Gets the starting position of a string: print (A.find (' B ')) results in 1, that is, the second digit.
Isalnum ()--detects whether numbers and uppercase and lowercase letters are included: print (A.isalnum ()) returns True
Isalpha ()--detects whether to include uppercase and lowercase
isdigit ()--to detect if a number is included
Islower ()--detects whether all lowercase letters
isspace ()--detects that all characters in a string are white space characters
Istitle ()--detects whether the initials uppercase
Isupper ()--detects whether all uppercase
joins ()--Connection string: print (A.join (' OK)) returns to Oabcdek
Lower ()--converts a string to lowercase
split ()--Split string: Print (A.split (' C ')) returns [' AB ', '] De '
Swapcase ()--converts lowercase to uppercase and converts the original capitalization to lowercase
title ()--capitalize the first letter of the word a= ' Hello word ' and return to Hello Word
Upper ()-- Converts a string to uppercase
Len (str)--Detect string length: Len (a) returns to 5

Index and fragmentation of strings:
accesses the character at the specified position in the string, 0 as the leading character, and-1 is the lowest character.
>>> a= ' abcde '
>>> a[1]
' B '
----------------------------------------------
> >> a[-1]
' e '
----------------------------------------------
[] can use the structure of [n:m], meaning to start with the nth character, and take the M character , but does not contain the M character
>>> a= ' ABCDEFG '
>>> a[0:5]
' ABCDE '

Original string:
starting with uppercase or lowercase r, where \ does not represent escape
>>> import os
>>> path=r ' C: '
>>> os.listdir ( Path
[' $360section ', ' $Recycle. Bin ', ' 360SANDBOX ', ' a.py ', ' AMD ', ' Autoexec.bat ', ' Bo
ot ', ' bootmgr ', ' bootsect . BAK ', ' cflog ', ' cimtemp ', ' Config.sys ', ' Documents and
 settings ', ' ghost.bat ', ' Ghost.exe ', ' grldr ', ' Grldr.mbr ', ' lbgsn ', ' lib ', ' Neo
Shineoffice 5 ', ' Okldr ', ' okldr.mbr ', ' OneKey.exe ', ' Oracle ', ' PerfLogs ', ' Progr
Am Files ', ' programdata ', ' Python34 ', ' System Volume information ', ' TeamViewer ',
  ' Temp ', ' Uninstall. ', ' Users ', ' Vb ', ' Vb7 ', ' vc# ', ' Windows ', ' Ylmf.ima ']

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.