Created
July 11, 2024 10:21
-
-
Save farhaduneci/1ed164d060dbc2e112347c8fc03a2989 to your computer and use it in GitHub Desktop.
VS Code Python Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Print to Console": { | |
"prefix": "print", | |
"body": [ | |
"print(${1:message})" | |
], | |
"description": "Insert a print statement" | |
}, | |
"If Statement": { | |
"prefix": "if", | |
"body": [ | |
"if ${1:condition}:", | |
"\t$0" | |
], | |
"description": "Insert an if statement" | |
}, | |
"If-Else Statement": { | |
"prefix": "ifelse", | |
"body": [ | |
"if ${1:condition}:", | |
"\t${2:pass}", | |
"else:", | |
"\t$0" | |
], | |
"description": "Insert an if-else statement" | |
}, | |
"For Loop": { | |
"prefix": "for", | |
"body": [ | |
"for ${1:item} in ${2:iterable}:", | |
"\t$0" | |
], | |
"description": "Insert a for loop" | |
}, | |
"For Loop with enumerate": { | |
"prefix": "forenum", | |
"body": [ | |
"for ${1:index}, ${2:item} in enumerate(${3:iterable}):", | |
"\t$0" | |
], | |
"description": "Insert a for loop with enumerate" | |
}, | |
"While Loop": { | |
"prefix": "while", | |
"body": [ | |
"while ${1:condition}:", | |
"\t$0" | |
], | |
"description": "Insert a while loop" | |
}, | |
"Function Definition": { | |
"prefix": "def", | |
"body": [ | |
"def ${1:function_name}(${2:args}):", | |
"\t\"\"\"${3:docstring}\"\"\"", | |
"\t$0" | |
], | |
"description": "Insert a function definition" | |
}, | |
"Class Definition": { | |
"prefix": "class", | |
"body": [ | |
"class ${1:ClassName}(${2:object}):", | |
"\t\"\"\"${3:docstring}\"\"\"", | |
"\tdef __init__(self, ${4:args}):", | |
"\t\t$0" | |
], | |
"description": "Insert a class definition" | |
}, | |
"Main Check": { | |
"prefix": "main", | |
"body": [ | |
"if __name__ == \"__main__\":", | |
"\t${1:main()}" | |
], | |
"description": "Insert a main guard" | |
}, | |
"List Comprehension": { | |
"prefix": "listcomp", | |
"body": [ | |
"[${1:expr} for ${2:item} in ${3:iterable}]" | |
], | |
"description": "Insert a list comprehension" | |
}, | |
"Dictionary Comprehension": { | |
"prefix": "dictcomp", | |
"body": [ | |
"{${1:key}: ${2:value} for ${3:key}, ${4:value} in ${5:iterable}.items()}" | |
], | |
"description": "Insert a dictionary comprehension" | |
}, | |
"Import Statement": { | |
"prefix": "imp", | |
"body": [ | |
"import ${1:module}" | |
], | |
"description": "Insert an import statement" | |
}, | |
"From Import Statement": { | |
"prefix": "fromimp", | |
"body": [ | |
"from ${1:module} import ${2:object}" | |
], | |
"description": "Insert a from import statement" | |
}, | |
"Try Except Block": { | |
"prefix": "tryexc", | |
"body": [ | |
"try:", | |
"\t$0", | |
"except ${1:Exception} as ${2:e}:", | |
"\t${3:print(str(e))}" | |
], | |
"description": "Insert a try-except block" | |
}, | |
"With Statement": { | |
"prefix": "with", | |
"body": [ | |
"with ${1:open(${2:file}, ${3:mode})} as ${4:f}:", | |
"\t$0" | |
], | |
"description": "Insert a with statement" | |
} | |
} |
Author
farhaduneci
commented
Jul 11, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment