Please enable JavaScript.
Coggle requires JavaScript to display documents.
PYTHON (Documentation (Built-in Data Types (Numeric Type (int (1), float…
PYTHON
Documentation
Comments
"#"
single Line
""" """
multiple Line
Built-in Data Types
Text type
str
'sdf'
"dasf"
"""adfdsf"""
the line breaks are inserted at the same position as in the code.
'''dsfdsaf'''
Numeric Type
int, float , complex
int
1
float
1.0
complex
1.0j
Sequence Type
list , tuple , range
Mapping type
dict
Set Types
set, frozenset
Boolean type
bool
Binary Types
bytes , bytearray , memoryview
data type
Function
type()
Setting specific Data Type
Built-in Modules
random
random.randrange()
return random Number
(START, STOP,STEP)
array
Data-type
b
1
B
1 signed char
u
2
h
H
i
I
l
array.array(dataType, [...vakues])
return arr~
.pop()
.insert(i, position)
.append()
.remove()
remove first occurence
index
.reverse()
Regular Expressions
re package
parameters
pattern
regex with '\n' and r'\n' both look for newline
formulaes
MetaCharaters
|
a or b
OR condition
Characters with special meaning
[ ]
SET OF CHARACTERS
\
Used with charachter sets
Signals a special sequence
.
Any character (except newline character)
EXCEPT NEW LINE
"he..o"
^
String
starts with
"^hello"
$
String ends with
"world$"
*
+
{ }
Exactly the specified number of occurrences
"al{2}"
()
Capture and group
Character Sets
\w
[a-zA-Z0-9_]
numbers
_
characters
\W
![a-zA-Z0-9_]
space included
OPPOSITE
OF \w
\A
Returns a match if the specified characters are at the beginning of the string
Checks only
beginning
"\AThe"
String
level
\b
Returns a match where the specified characters are at the beginning or at the end of a word
Word
specific
check its begin or end
r"\bain"
check words start
r"ain\b"
check word end
using with different chareater sets is diificult
\B
Returns a match where the specified characters are present, but NOT at the beginning (or at the end) of a word
Word specific
opposite of \b
using at sentence level is difficult.
r"\Bain"
it should not start with then it will return but exist in word.
Check if "ain" is present, but NOT at the beginning of a word:
r"ain\B"
It should not be at the end but should exist in the word
Check if "ain" is present, but NOT at the end of a word
\d
0-9
digits
\D
opposite of \d
no digits
\s
Return a match at every white-space character
space
\S
! \S
not space
\Z
Returns a match if the specified characters are at the end of the strin
String
level
check its
end
opposite of \A
quantifiers
+
1 or more
Greedy
?
0 or 1
*
0 or more
Greedy
{n,m}
n to m repetitions
{,3}
1 more item...
{0,}
1 more item...
Greedy
They are used after the Character Sets
SET [ ]
return finded
characters
.
works only on characters
[a-n]
search from a to n charachters
[arn]
[01234]
[0-9]
1 more item...
[^arn]
except arn
[+]
In sets, +, *, ., |, (), $,{} has no special meaning, so [+] means: return a match for any + character in the string
string
r'\n' means it's a raw string with two characters 'n' and '\' as
opposed to just one special character'
flag
import re
FUNCTIONS
search()
return
none
match
searches anywhere in the sentence
match()
only beginning of the string
match doesn't work with newline
findall()
find all pulls out all instances
finditer()
Object
match
.span()
return tuple with start - end position of match
.string
return string
.group()
return the string where match was found
Tips & Tricks
x, y, z = "Orange", "Banana", "Cherry"
Assign to multiple value.
Funtions
bool( )
True
Except these all other values return True.
False
If a False value is passed.
If None is passed.
If an empty sequence is passed, such as (), [], ”, etc
If Zero is passed in any numeric type, such as 0, 0.0 etc
If an empty mapping is passed, such as {}.
If Objects of Classes having
bool
() or
len()
method, returning 0 or False
If no parameter is passed, then by default it returns False.
Data Stucture
Array
re.match(pattern, string, flags)
re.search(pattern, string, flags)
searches anywhere in the sentence
only beginning of the string
findall
Returns a list containing all matches
split
Returns a list where the string has been split at each match
sub
a list containing all matches