Python
cotrTypeCompare
Python Type Comparison
# Check if two variables have the same type:if type(${1:variable1}) is type(${2:variable2}): # Your code here
cotrTypesString
Python String Type
str
cotrOperators
Python Mathematical Operators
# Python Mathematical Operators# Addition: +# Subtraction: -# Multiplication: *# Division: /# Modulus (Remainder): %# Exponentiation: **# Floor Division: //# Increment: Not supported in Python# Decrement: Not supported in Python# Assignment: =# Addition assignment: +=# Subtraction assignment: -=# Multiplication assignment: *=# Division assignment: /=# Modulus assignment: %=# Exponentiation assignment: **=# Floor Division assignment: //=
cotrTypesBool
Python Boolean Type
bool
cotrTypesList
Python List Type
list
cotrVarMap
Python Create Dictionary Variable
${1:myDict} = { '${2:key1}': ${3:value1}, '${4:key2}': ${5:value2}}
cotrIfElse
Python If Else Statement
if ${1:condition}: # Your code hereelse: # Your code here
cotrTypesInt
Python Integer Type
int
cotrVarNum
Python Create Integer Variable
${1:myInt} = ${2:0}
cotrVarNumAlt
Python Create Float Variable
${1:myFloat} = ${2:0.0}
cotrComment
Python Comment
# ${1:Your comment here}
cotrCommentMulti
Python Multi-Line Comment
'''${1:Your comment here}'''
cotrIf
Python If Statement
if ${1:condition}: # Your code here
cotrTypeCheck
Python Type Check
type(${1:variable})
cotrTypes
Python Types
$BLOCK_COMMENT_STARTPython is a dynamically typed language.
Some common types in Python include:- int: Integer- float: Floating-point number- complex: Complex number- str: String- bool: Boolean- list: List- tuple: Tuple- set: Set- dict: Dictionary- NoneType: Represents the absence of a value- bytes: Byte sequence- bytearray: Mutable byte sequence- memoryview: Memory view object- range: Range object- frozenset: Immutable set- object: Base class for all Python classes- function: Function object- type: Type object- class: Custom class defined by the user- module: Module object- file: File object- Exception: Base class for all exceptions$BLOCK_COMMENT_END
cotrTypesNum
Python Float Type
float
cotrTypesDate
Python Date Type
from datetime import datetime
cotrTypesMap
Python Dictionary Type
dict
cotrVarDate
Python Create Date Variable
from datetime import datetime
my_date = datetime(${1:year}, ${2:month}, ${3:day})
cotrForLoop
Python For Loop
for ${1:i} in range(${2:10}): # Your code here
cotrEnum
Python Enum
class ${1:MyEnum}(Enum): ${2:value1} = ${3:1} ${4:value2} = ${5:2} # Add more values here
cotrEqual
Python Equal To
==
cotrPrint
Python Print
print(${1:'Your message here'})
cotrThrow
Python Throw Exception
raise ${1:Exception('Your message here')}
cotrNotEqual
Python Not Equal To
!=
cotrNow
Python Date Now
from datetime import datetime
now = datetime.now()
cotrForInLoop
Python For…In Loop
for ${1:item} in ${2:iterable}: # Your code here
cotrFunc
Python Function
def ${2:my_function}(${3:parameters}): ${4:# Your code here}
cotrEntry
Python Entry Point
# Python Entry Point# To run this program, use: `python filename.py`
if __name__ == '__main__': # Your code here
cotrTypeConvert
Python Type Conversion
# Python Type Conversion:
# Implicit conversions (Python performs automatically):# - Can be unpredictable, especially with loose equality (==).
# Explicit conversions:# - int(variable) // Converts to integer# - float(variable) // Converts to float# - str(variable) // Converts to string# - bool(variable) // Converts to boolean
# Note:# - Be aware of implicit conversions and use explicit conversions when necessary for clarity and control.
cotrTypesDynamic
Python Dynamic Type
Any # Note: Python is dynamically typed. Use the Typing module to specify types.
cotrVarList
Python Create List Variable
${1:myList} = [${2:1}, ${3:2}, ${4:3}]
cotrFuncArrow
Python Arrow Function
${2:my_function} = lambda ${3:parameters}: ${4:// Your code here}
cotrFuncSyntax
Python Function Syntax
# Python Function Syntax# Basic function: def function_name(parameters): ...# Function with arguments: def function_name(arg1, arg2, ...): ...# Function with named arguments: def function_name(*, arg1=value1, arg2=value2, ...): ...
cotrClass
Python Class
class ${1:MyClass}: # Your code here
cotrInfo
Python Info
Typing: Dynamically typed. Use the Typing module to specify types.Paradigm: Multi-paradigm: object-oriented, imperative, functional, procedural, reflectiveCompilation: InterpretedConcurrency: Supports multi-threading and asynchronous programming with asyncio
cotrVar
Python Create Variable
${1:myVar} = ${2:value}
cotrVarBool
Python Create Boolean Variable
${1:myBool} = ${2:True}
cotrTypesBoolFalse
Python Boolean False
False
cotrInterpolate
Python Interpolate String
f"${1:Your message here}"
cotrConcat
Python Concatenate String
"${1:Your message here}" + "${2:Another message}"
cotrPrintMulti
Python Print Multi
print('''${1:Line 1}${2:Line 2}${3:Line 3}''')
cotrTypesBoolTrue
Python Boolean True
True
cotrVarNullable
Python Create Nullable Variable
${1:my_var} = None # Variable can be set to None.
cotrTernary
Python Ternary Operator
${1:trueValue} if ${2:condition} else ${3:falseValue}
cotrNull
Python Null Type
None
cotrVarTyped
Python Create Typed Variable
${1:my_var} = $2 # Note: Python is dynamically typed.
cotrConst
Python Create Constant
${1:MY_CONST} = ${2:value}
cotrFuncArgs
Python Function Args
# In Python, functions can have arguments with default values.def ${2:my_function}(${3:arg1}, ${4:arg2}=${5:'defaultVal'}): ${6:# Your code here}
cotrVarStringMulti
Python Create Multi-Line String Variable
${1:myString} = '''${2:Line 1}${3:Line 2}${4:Line 3}'''
cotrFuncArgsNamed
Python Function Named Args
def ${2:my_function}(*, ${3:arg1}=${4:value1}, ${5:arg2}=${6:value2}): ${7:# Your code here}
cotrTryCatch
Python Try Except
try: # Your code hereexcept ${1:Exception} as ${2:e}: # Your code here
cotrStructure
Python Project Structure (High-Level)
# Recommended High-Level Python Project Structure:
# - /# - README.md: Project description and instructions.# - setup.py: Package and dependency configuration.# - requirements.txt: List of dependencies for pip.# - .env: Environment-specific configurations.
# - src/# - Contains all the source code of the project.# - /package_name/# - __init__.py: Makes Python treat directories as containing packages.# - main.py: Entry point of the application.# - /module1/# - /module2/
# - tests/# - Contains test files.# - /unit/# - /integration/
# - docs/# - Documentation files for the project.
# - data/# - Data files used in the project (if applicable).
# - scripts/# - Utility scripts for deployment, setup, etc.
# Note:# - This structure is adaptable and can be modified according to the project's needs.# - Use virtual environments to isolate project-specific dependencies.
cotrOperatorsBool
Python Boolean Operators
# Python Boolean Operators# Logical AND: and# Logical OR: or# Logical NOT: not# Equality: ==# Inequality: !=# Greater than: ># Less than: <# Greater than or equal to: >=# Less than or equal to: <=
cotrVarSyntax
Variable Declaration Syntax
# Python Variable Declaration Syntax:
# - Python is dynamically typed, so there is no explicit type declaration.# - Variables are created when you first assign a value to them.# - Variables can be reassigned to different types.
# Note:# - Python does not have direct equivalents to 'var', 'let', or 'const'.# - Use descriptive variable names to improve code readability.
cotrVarString
Python Create String Variable
${1:myString} = ${2:''}
cotrWhileLoop
Python While Loop
while ${1:condition}: # Your code here