Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

6 Commits

Repository files navigation

Python Snippets Pack for Visual Studio Code (python 3^)

A snippet pack to make you more productive working with python

This snippet pack contains all below python method

  • all python built-in snippets and contains at least one example for each method
  • all python string snippets contains at least one example for each method
  • all python list snippets contains at least one example for each method
  • all python sets snippets contains at least one example for each method
  • all python tuple snippets contains at least one example for each method
  • all python dictionary snippets contains at least one example for each method
  • And contains a lot of other code snippets (like if/else, for, while, while/else, try/catch,file process and
  • class snippets and class examples for oop(polymorphism,encapsulation,inheritance .i.g)

if you don't use a method don't worry this extension contains a lot of code examples for each python method

This extensions not only snippets but also it will be helpful for learning python programming language.

You will learn all python method with a lot of code examples

For example if you want to use string replace method then only use .replace

But if you dont know how to use replace method then use string.replace=>

Here's the full list of all the snippets:

Snippets / Descriptons

built-in methods code snippetsDescription
absReturns the absolute value of a number
allReturns True if all items in an iterable object are true
anyReturns True if any item in an iterable object is true
asciiReturns a readable version of an object. Replaces none-ascii characters with escape character
binReturns the binary version of a number
boolReturns the boolean value of the specified object
bytearrayReturns an array of bytes
bytesReturns a bytes object
callableReturns True if the specified object is callable, otherwise False
chrReturns a character from the specified Unicode code.
delattrDeletes the specified attribute (property or method) from the specified object
dictReturns a dictionary (Array)
dirReturns a list of the specified object's properties and methods
divmodReturns the quotient and the remainder when argument1 is divided by argument2
enumerateTakes a collection (e.g. a tuple) and returns it as an enumerate object
evalEvaluates and executes an expression
execExecutes the specified code (or object)
filterUse a filter function to exclude items in an iterable object
floatReturns a floating point number
frozensetReturns a frozenset object
getattrReturns the value of the specified attribute (property or method)
globalsReturns the current global symbol table as a dictionary
hasattrReturns True if the specified object has the specified attribute (property/method)
hashReturns the hash value of a specified object
helpExecutes the built-in help system
hexConverts a number into a hexadecimal value
intReturns an integer number
idReturns the id of an object
inputAllowing user input
isinstanceReturns True if a specified object is an instance of a specified object
issubclassReturns True if a specified class is a subclass of a specified object
iterReturns an iterator object
lenReturns the length of an object
localsReturns an updated dictionary of the current local symbol table
mapReturns the specified iterator with the specified function applied to each item
maxReturns the largest item in an iterable
memoryviewReturns a memory view object
minReturns the smallest item in an iterable
nextReturns the next item in an iterable
objectReturns a new object
octConverts a number into an octal
openOpens a file and returns a file object
ordGiven a string of length one, return an integer representing the Unicode code point of the character when the argument is a unicode object, or the value of the byte when the argument is an 8-bit string.
powReturn x to the power y
printPrints to the standard output device
propertyGets, sets, deletes a property
rangeReturns a sequence of numbers, starting from 0 and increments by 1 (by default)
reprReturns a readable version of an object
reversedReturns a reversed iterator
roundRounds a numbers
sliceReturns a slice object
sortedReturns a sorted list
staticmethodConverts a method into a static method
strReturns a string object
sumSums the items of an iterator
superReturn a proxy object that delegates method calls to a parent or sibling class of type.
typeReturns the type of an object
unichrReturn the Unicode string of one character whose Unicode code is the integer i.
varsReturns the dict property of an object
zip Returns an iterator, from two or more iterators

built-in methods code examplesDescription
built_in.abs=>intAn example for using abs method
built_in.abs=>floatAn example for using abs method
built_in.abs=>complexAn example for using abs method
built_in.all=>list_1An example for using all with list
built_in.all=>list_2An example for using all with list
built_in.all=>tupleAn example for using all with tuple
built_in.all=>setAn example for using all with set
built_in.all=>dictionaryAn example for using all with dictionary
built_in.any=>list_1An example for using all with list
built_in.ascii=>_list_1An example for using ascii
built_in.bin=>_1An example for using ascii
built_in.bool=>_1An example for using bool
built_in.bytearray=>_1An example for using bool
built_in.bytes=>_1An example for using bytes
built_in.callable=>_1An example for using callable
built_in.callable=>_2An example for using bytes
built_in.chr=>_1An example for using bytes
built_in.compile=>_1An example for using compile
built_in.compile=>_1An example for using compile
built_in.complex=>_1An example for using complex
built_in.complex=>_2An example for using complex
built_in.delattr=>_1An example for using delattr
built_in.dict=>_1An example for using dict
built_in.dir=>An example for using dict
built_in.divmod=>_1An example for using divmod
built_in.enumerate=>_1An example for using enumerate
built_in.eval=>_1An example for using eval
built_in.exec=>_1An example for using exec
built_in.filter=>_1An example for using filter
built_in.float=>_1An example for using float
built_in.float=>_2An example for using float
built_in.format=>_1An example for using format
built_in.frozenset=>_1An example for using frozenset
built_in.frozenset=>_2An example for using frozenset
built_in.frozenset=>_3An example for using frozenset
built_in.globals=>_1An example for using globals
built_in.globals=>_2An example for using globals
built_in.hasattr=>An example for using hasattr
built_in.hex=>An example for using hasattr
built_in.int=>_1An example for using int
built_in.int=>_2An example for using int
built_in.id=>An example for using id
built_in.input=>_1An example for using input
built_in.input=>_2An example for using input
built_in.isinstance=>_1An example for using isinstance
built_in.isinstance=>_2An example for using isinstance
built_in.isinstance=>_3An example for using isinstance
built_in.issubclass=>An example for using isinstance
built_in.iter=>An example for using iter
built_in.len=>_1An example for using len
built_in.len=>_2An example for using len
built_in.list=>An example for using list
built_in.locals=>_1An example for using locals
built_in.locals=>_2An example for using locals
built_in.map=>_1An example for using map
built_in.map=>_2An example for using map
built_in.max=>_1An example for using max
built_in.max=>_2An example for using max
built_in.max=>_3An example for using max
built_in.memoryview=>An example for using memoryview
built_in.min=>_1An example for using min
built_in.min=>_2An example for using min
built_in.min=>_3An example for using min
built_in.next=>_1An example for using next
built_in.next=>_2An example for using next
built_in.object=>An example for using object
built_in.oct=>An example for using oct
built_in.open=>An example for using open
built_in.ord=>An example for using ord
built_in.pow=>An example for using pow
built_in.print=>_1An example for using print
built_in.print=>_2An example for using print
built_in.print=>_3An example for using print
built_in.property=>An example for using property
built_in.range=>_1An example for using range
built_in.range=>_2An example for using range
built_in.range=>_3An example for using range
built_in.reversed=>An example for using reversed
built_in.round=>_1An example for using round
built_in.round=>_2An example for using round
built_in.set=>An example for using set
built_in.setattr=>An example for using setattr
built_in.slice=>_1An example for using slice
built_in.slice=>_2An example for using slice
built_in.slice=>_3An example for using slice
built_in.sorted=>_1An example for using sorted
built_in.sorted=>_2An example for using sorted
built_in.sorted=>_3An example for using sorted
built_in.str=>An example for using str
built_in.sum=>_1An example for using sum
built_in.sum=>_2An example for using sum
built_in.tuple=>An example for using tuple
built_in.type=>An example for using type
built_in.vars=>An example for using vars
built_in.zip=>_1An example for using zip
built_in.zip=>_2 An example for using zip

string methods code snippetsDescription
.capitalizeConverts the first character to upper case
.casefoldConverts string into lower case
.centerReturns a centered string
.countReturns the number of times a specified value occurs in a string
.encodeReturns an encoded version of the string
.endswithReturns true if the string ends with the specified value
.expandtabsSets the tab size of the string
.findSearches the string for a specified value and returns the position of where it was found
.formatFormats specified values in a string
.format_mapFormats specified values in a string
.indexSearches the string for a specified value and returns the position of where it was found
.isalnumReturns True if all characters in the string are alphanumeric
.isalphaReturns True if all characters in the string are in the alphabet
.isdecimalReturns True if all characters in the string are decimals
.isdigitReturns True if all characters in the string are digits
.isidentifierReturns True if the string is an identifier
.islowerReturns True if all characters in the string are lower case
.isnumericReturns True if all characters in the string are numeric
.isprintableReturns True if all characters in the string are printable
.isspaceReturns True if all characters in the string are whitespaces
.istitleReturns True if the string follows the rules of a title
.isupperReturns True if all characters in the string are upper case
.joinJoins the elements of an iterable to the end of the string
.ljustReturns a left justified version of the string
.lowerConverts a string into lower case
.lstripReturns a left trim version of the string
.maketransReturns a translation table to be used in translations
.partitionReturns a tuple where the string is parted into three parts
.replaceReturns a string where a specified value is replaced with a specified value
.rfindSearches the string for a specified value and returns the last position of where it was found
.rindexSearches the string for a specified value and returns the last position of where it was found
.rpartitionReturns a tuple where the string is parted into three parts
.rsplitReturns a right trim version of the string
.splitSplits the string at the specified separator, and returns a list
.splitlinesSplits the string at line breaks and returns a list
.startswithReturns true if the string starts with the specified value
.swapcaseSwaps cases, lower case becomes upper case and vice versa
.titleConverts the first character of each word to upper case
.translateReturns a translated string
.upperConverts a string into upper case
.zfill Fills the string with a specified number of 0 values at the beginning

string methods code examplesDescription
string.capitalize=>_1An example for using capitalize
string.capitalize=>_2An example for using capitalize
string.casefold=>An example for using casefold
string.center=>_1An example for using center
string.center=>_2An example for using center
string.count=>_1An example for using count
string.count=>_2An example for using count
string.encode=>An example for using encode
string.endswith=>_1An example for using endswith
string.endswith=>_2An example for using endswith
string.expandtabs=>_1An example for using expandtabs
string.expandtabs=>_2An example for using expandtabs
string.find=>_1An example for using find
string.find=>_2An example for using find
string.find=>_3An example for using find
string.find=>_4An example for using find
string.format=>An example for using format
string.format_map=>An example for using format_map
string.index=>_1An example for using index
string.index=>_2An example for using index
string.index=>_3An example for using index
string.index=>_4An example for using index
string.isalnum=>An example for using isalnum
string.isalpha=>An example for using isalpha
string.isdecimal=>An example for using isdecimal
string.isdigit=>An example for using isdigit
string.isidentifier=>An example for using isidentifier
string.islower=>An example for using islower
string.isnumeric=>An example for using isnumeric
string.isprintable=>An example for using isprintable
string.isspace=>An example for using isspace
string.istitle=>An example for using istitle
string.isupper=>An example for using isupper
string.join=>An example for using join
string.ljust=>An example for using ljust
string.lower=>An example for using lower
string.lstrip=>An example for using lstrip
string.maketrans=>An example for using maketrans
string.partition=>An example for using partition
string.replace=>An example for using replace
string.rfind=>An example for using rfind
string.rindex=>An example for using rindex
string.rpartition=>An example for using rpartition
string.rsplit=>An example for using rsplit
string.split=>An example for using split
string.splitlines=>An example for using splitlines
string.startswith=>An example for using startswith
string.swapcase=>An example for using swapcase
string.title=>An example for using title
string.translate=>An example for using translate
string.upper=>An example for using upper
string.zfill=> An example for using zfill

list methods code snippetsDescription
.appendAdds an element at the end of the list
.clearRemoves all the elements from the list
.copyReturns a copy of the list
.countReturns the number of elements with the specified value
.extendAdd the elements of a list (or any iterable), to the end of the current list
.indexReturns the index of the first element with the specified value
.insertAdds an element at the specified position
.popRemoves the element at the specified position
.removeRemoves the first item with the specified value
.reverseReverses the order of the list
.sort Sorts the list

list methods code examplesDescription
list.append=>An example for using append
list.clear=>An example for using clear
list.copy=>An example for using copy
list.count=>An example for using count
list.extend=>An example for using extend
list.index=>An example for using index
list.insert=>An example for using insert
list.pop=>An example for using pop
list.remove=>An example for using remove
list.reverse=>An example for using reverse
list.sort=>An example for using sort
list.comp=>_1An example for using list comprehension
list.comp=>_2An example for using list comprehension
list.comp=>_3An example for using list comprehension
list.comp=>_4An example for using list comprehension
list.comp=>_5 An example for using list comprehension

sets methods code snippetsDescription
.addAdds an element to the set
.clearRemoves all the elements from the set
.copyReturns a copy of the set
.differenceReturns a set containing the difference between two or more sets
.difference_updateRemoves the items in this set that are also included in another, specified set
.discardRemove the specified item
.intersectionReturns a set, that is the intersection of two other sets
.intersection_updateRemoves the items in this set that are not present in other, specified set(s)
.isdisjointReturns whether two sets have a intersection or not
.issubsetReturns whether another set contains this set or not
.issupersetReturns whether this set contains another set or not
.popRemoves the specified element
.removeRemoves the specified element
.symmetric_differenceReturns a set with the symmetric differences of two sets
.symmetric_difference_updateinserts the symmetric differences from this set and another
.unionReturn a set containing the union of sets
.update Update the set with the union of this set and others

sets methods code examplesDescription
sets.add=>An example for using add
sets.clear=>An example for using clear
sets.copy=>An example for using copy
sets.difference=>_1An example for using difference
sets.difference=>_2An example for using difference
sets.difference_update=>An example for using difference_update
sets.discard=>An example for using discard
sets.intersection=>_1An example for using intersection
sets.intersection=>_2An example for using intersection
sets.intersection_update=>_1An example for using intersection_update
sets.intersection_update=>_2An example for using intersection_update
sets.isdisjoint=>_1An example for using isdisjoint
sets.isdisjoint=>_2An example for using isdisjoint
sets.sets.issubset=>_1An example for using issubset
sets.issubset=>_2An example for using issubset
sets.issuperset=>_1An example for using issuperset
sets.issuperset=>_2An example for using issuperset
sets.pop=>An example for using pop
sets.remove=>An example for using remove
sets.symmetric_difference=>An example for using symmetric_difference
sets.symmetric_difference_update=>An example for using symmetric_difference_update
sets.union=>_1An example for using union
sets.union=>_2An example for using union
sets.update=> An example for using update

dictionary methods code snippetsDescription
.clearRemoves all the elements from the dictionary
.copyReturns a copy of the dictionary
.fromkeysReturns a dictionary with the specified keys and values
.getReturns the value of the specified key
.itemsReturns a list containing the a tuple for each key value pair
.keysReturns a list containing the dictionary's keys
.popRemoves the element with the specified key
.popitemRemoves the last inserted key-value pai
.setdefaultReturns the value of the specified key. If the key does not exist: insert the key, with the specified value
.updateUpdates the dictionary with the specified key-value pairs
.values Returns a list of all the values in the dictionary
dictionary methods code examplesDescription
dictionary.clear=>An example for using clear
dictionary.copy=>An example for using copy
dictionary.fromkeys=>An example for using fromkeys
dictionary.get=>An example for using get
dictionary.items=>An example for using items
dictionary.keys=>An example for using keys
dictionary.pop=>An example for using pop
dictionary.popitem=>An example for using popitem
dictionary.setdefault=>An example for using setdefault
dictionary.update=>An example for using update
dictionary.values=> An example for using values

tuple methods code snippetsDescription
.countReturns the number of times a specified value occurs in a tuple
.index Searches the tuple for a specified value and returns the position of where it was found
tuple methods code examplesDescription
tuple.count=>An example for using count
tuple.index=> An example for using index

for loop code snippetsDescription
for for Statements
for loop code examples
for=>An example for using for
for=>through_a_stringAn example for using for
for=>break_statementAn example for using for
for=>continue_statementAn example for using for
for=>range_function_1An example for using for
for=>range_function_2An example for using for
for=>range_function_3An example for using for
for=>for_elseAn example for using for
for=>for_else An example for using for

while loop code snippetsDescription
whilewhile Statements
while_else while Statements
while loop code examplesDescription
while=>while Statements
while=>break_statementwhile Statements
while=>continue_statement while Statements

if/else statement code snippetsDescription
ifif Statements
ifelifif/else if Statements
ifelifelseif/else if/else Statements
ifelseif/else Statements
ifshortifshort Statements
else else Statements

class code snippetsDescription
class=>python class
init=>class init method
iter=>class iter method
next=> class next method
class code examplesDescription
class=>_1oop inheritance example
class=>inheritance_1oop inheritance example
class=>inheritance_2oop inheritance example
class=>with_attribute_1class with attribute example
class=>with_attribute_2class with attribute example
class=>with_attribute_3class with attribute example
class=>with_method_1class with method example
class=>with_method_2class with method example
class=>encapsulationclass encapsulation example
class=>polymorphism class polymorphism example

import code snippetsDescription
import=> import module

List Comprehensions code snippetsDescription
comp=> List Comprehensions

List Comprehensions code examplesDescription
list.comp=>_1An example for using list comprehension
list.comp=>_2An example for using list comprehension
list.comp=>_3An example for using list comprehension
list.comp=>_4An example for using list comprehension
list.comp=>_5An example for using list comprehension

lambda code examplesDescription
lambda A lambda function can take any number of arguments, but can only have one expression.

function code snippetsDescription
def=>Defining Function
def=>with_default_valueDefining Function wqith default values
function=> Defining Function

file code examplesDescription
file=>openFileopen a file
file=>openFileReadLineRead one line of the file
file=>writeExistFileWrite to an Existing File
file=>writeOwerWriteOpen a file and overwrite the content
file=>createFileIfDoesNotExistCreate a new file if it does not exist
file=>createFileCreate a new file
file=>deleteFile delete a file

For example

Creating a class

class=>with_attribute_1

class Parrot:
# class attribute
species = 'bird'
# instance attribute
def __init__(self, name, age):
self.name = name
self.age = age
# instantiate the Parrot class
blu = Parrot('Blu', 10)
woo = Parrot('woo', 15)
# access the class attributes
print('Blu is a {}'.format(blu.__class__.species))
print('Woo is also a {}'.format(woo.__class__.species))
# access the instance attributes
print('{} is {} years old'.format( blu.name, blu.age))
print('{} is {} years old'.format( woo.name, woo.age))

Release Notes

Users appreciate release notes as you update your extension.

For more information

Enjoy!

1.0.0

Initial release of python code snippets

1.0.2

Updated README.md


About

This repo contains a lot of snippets for python (examples for all built-in, string, list, set, dictionary, tuple methods and for,while try/catch, class and oop) in VS Code

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors