├── .gitignore ├── LICENSE ├── README.md ├── icon.png ├── package.json ├── python.gif └── snippets └── python_snippets.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.vsix 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ferhat Yalcin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Python Snippets Pack for Visual Studio Code (python 3^) 2 | 3 | #### A snippet pack to make you more productive working with python 4 | 5 | #### This snippet pack contains all below python method 6 | * all python built-in snippets and contains at least one example for each method 7 | * all python string snippets contains at least one example for each method 8 | * all python list snippets contains at least one example for each method 9 | * all python sets snippets contains at least one example for each method 10 | * all python tuple snippets contains at least one example for each method 11 | * all python dictionary snippets contains at least one example for each method 12 | * And contains a lot of other code snippets (like if/else, for, while, while/else, try/catch,file process and 13 | * class snippets and class examples for oop(polymorphism,encapsulation,inheritance .i.g) 14 | 15 | #### if you don't use a method don't worry this extension contains a lot of code examples for each python method 16 | #### This extensions not only snippets but also it will be helpful for learning python programming language. 17 | #### You will learn all python method with a lot of code examples 18 | #### For example if you want to use string replace method then only use .replace 19 | #### But if you dont know how to use replace method then use string.replace=> 20 | 21 | 22 | ![](python.gif) 23 | 24 |       25 |       26 | 27 | ### Here's the full list of all the snippets: 28 | 29 | ## Snippets / Descriptons 30 | 31 | | built-in methods code snippets | Description | 32 | | --- | --- | 33 | | abs | Returns the absolute value of a number | 34 | | all | Returns True if all items in an iterable object are true | 35 | | any | Returns True if any item in an iterable object is true | 36 | | ascii | Returns a readable version of an object. Replaces none-ascii characters with escape character | 37 | | bin | Returns the binary version of a number | 38 | | bool | Returns the boolean value of the specified object | 39 | | bytearray | Returns an array of bytes | 40 | | bytes | Returns a bytes object | 41 | | callable | Returns True if the specified object is callable, otherwise False | 42 | | chr | Returns a character from the specified Unicode code. | 43 | | delattr | Deletes the specified attribute (property or method) from the specified object | 44 | | dict | Returns a dictionary (Array) | 45 | | dir | Returns a list of the specified object's properties and methods | 46 | | divmod | Returns the quotient and the remainder when argument1 is divided by argument2 | 47 | | enumerate | Takes a collection (e.g. a tuple) and returns it as an enumerate object | 48 | | eval | Evaluates and executes an expression | 49 | | exec | Executes the specified code (or object) | 50 | | filter | Use a filter function to exclude items in an iterable object | 51 | | float | Returns a floating point number | 52 | | frozenset | Returns a frozenset object | 53 | | getattr | Returns the value of the specified attribute (property or method) | 54 | | globals | Returns the current global symbol table as a dictionary | 55 | | hasattr | Returns True if the specified object has the specified attribute (property/method) | 56 | | hash | Returns the hash value of a specified object | 57 | | help | Executes the built-in help system | 58 | | hex | Converts a number into a hexadecimal value | 59 | | int | Returns an integer number | 60 | | id | Returns the id of an object | 61 | | input | Allowing user input | 62 | | isinstance | Returns True if a specified object is an instance of a specified object | 63 | | issubclass | Returns True if a specified class is a subclass of a specified object | 64 | | iter | Returns an iterator object | 65 | | len | Returns the length of an object | 66 | | locals | Returns an updated dictionary of the current local symbol table | 67 | | map | Returns the specified iterator with the specified function applied to each item | 68 | | max | Returns the largest item in an iterable | 69 | | memoryview | Returns a memory view object | 70 | | min | Returns the smallest item in an iterable | 71 | | next | Returns the next item in an iterable | 72 | | object | Returns a new object | 73 | | oct | Converts a number into an octal | 74 | | open | Opens a file and returns a file object | 75 | | ord | Given 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. | 76 | | pow | Return x to the power y | 77 | | print | Prints to the standard output device | 78 | | property | Gets, sets, deletes a property | 79 | | range | Returns a sequence of numbers, starting from 0 and increments by 1 (by default) | 80 | | repr | Returns a readable version of an object | 81 | | reversed | Returns a reversed iterator | 82 | | round | Rounds a numbers | 83 | | slice | Returns a slice object | 84 | | sorted | Returns a sorted list | 85 | | staticmethod | Converts a method into a static method | 86 | | str | Returns a string object | 87 | | sum | Sums the items of an iterator | 88 | | super | Return a proxy object that delegates method calls to a parent or sibling class of type. | 89 | | type | Returns the type of an object | 90 | | unichr | Return the Unicode string of one character whose Unicode code is the integer i. | 91 | | vars | Returns the __dict__ property of an object | 92 | | zip                                                                     | Returns an iterator, from two or more iterators | 93 | 94 |       95 |       96 | 97 | | built-in methods code examples | Description | 98 | | --- | --- | 99 | | built_in.abs=>int | An example for using abs method | 100 | | built_in.abs=>float | An example for using abs method | 101 | | built_in.abs=>complex | An example for using abs method | 102 | | built_in.all=>list_1 | An example for using all with list | 103 | | built_in.all=>list_2 | An example for using all with list | 104 | | built_in.all=>tuple | An example for using all with tuple | 105 | | built_in.all=>set | An example for using all with set | 106 | | built_in.all=>dictionary | An example for using all with dictionary | 107 | | built_in.any=>list_1 | An example for using all with list | 108 | | built_in.ascii=>_list_1 | An example for using ascii | 109 | | built_in.bin=>_1 | An example for using ascii | 110 | | built_in.bool=>_1 | An example for using bool | 111 | | built_in.bytearray=>_1 | An example for using bool | 112 | | built_in.bytes=>_1 | An example for using bytes | 113 | | built_in.callable=>_1 | An example for using callable | 114 | | built_in.callable=>_2 | An example for using bytes | 115 | | built_in.chr=>_1 | An example for using bytes | 116 | | built_in.compile=>_1 | An example for using compile | 117 | | built_in.compile=>_1 | An example for using compile | 118 | | built_in.complex=>_1 | An example for using complex | 119 | | built_in.complex=>_2 | An example for using complex | 120 | | built_in.delattr=>_1 | An example for using delattr | 121 | | built_in.dict=>_1 | An example for using dict | 122 | | built_in.dir=> | An example for using dict | 123 | | built_in.divmod=>_1 | An example for using divmod | 124 | | built_in.enumerate=>_1 | An example for using enumerate | 125 | | built_in.eval=>_1 | An example for using eval | 126 | | built_in.exec=>_1 | An example for using exec | 127 | | built_in.filter=>_1 | An example for using filter | 128 | | built_in.float=>_1 | An example for using float | 129 | | built_in.float=>_2 | An example for using float | 130 | | built_in.format=>_1 | An example for using format | 131 | | built_in.frozenset=>_1 | An example for using frozenset | 132 | | built_in.frozenset=>_2 | An example for using frozenset | 133 | | built_in.frozenset=>_3 | An example for using frozenset | 134 | | built_in.globals=>_1 | An example for using globals | 135 | | built_in.globals=>_2 | An example for using globals | 136 | | built_in.hasattr=> | An example for using hasattr | 137 | | built_in.hex=> | An example for using hasattr | 138 | | built_in.int=>_1 | An example for using int | 139 | | built_in.int=>_2 | An example for using int | 140 | | built_in.id=> | An example for using id | 141 | | built_in.input=>_1 | An example for using input | 142 | | built_in.input=>_2 | An example for using input | 143 | | built_in.isinstance=>_1 | An example for using isinstance | 144 | | built_in.isinstance=>_2 | An example for using isinstance | 145 | | built_in.isinstance=>_3 | An example for using isinstance | 146 | | built_in.issubclass=> | An example for using isinstance | 147 | | built_in.iter=> | An example for using iter | 148 | | built_in.len=>_1 | An example for using len | 149 | | built_in.len=>_2 | An example for using len | 150 | | built_in.list=> | An example for using list | 151 | | built_in.locals=>_1 | An example for using locals | 152 | | built_in.locals=>_2 | An example for using locals | 153 | | built_in.map=>_1 | An example for using map | 154 | | built_in.map=>_2 | An example for using map | 155 | | built_in.max=>_1 | An example for using max | 156 | | built_in.max=>_2 | An example for using max | 157 | | built_in.max=>_3 | An example for using max | 158 | | built_in.memoryview=> | An example for using memoryview | 159 | | built_in.min=>_1 | An example for using min | 160 | | built_in.min=>_2 | An example for using min | 161 | | built_in.min=>_3 | An example for using min | 162 | | built_in.next=>_1 | An example for using next | 163 | | built_in.next=>_2 | An example for using next | 164 | | built_in.object=> | An example for using object | 165 | | built_in.oct=> | An example for using oct | 166 | | built_in.open=> | An example for using open | 167 | | built_in.ord=> | An example for using ord | 168 | | built_in.pow=> | An example for using pow | 169 | | built_in.print=>_1 | An example for using print | 170 | | built_in.print=>_2 | An example for using print | 171 | | built_in.print=>_3 | An example for using print | 172 | | built_in.property=> | An example for using property | 173 | | built_in.range=>_1 | An example for using range | 174 | | built_in.range=>_2 | An example for using range | 175 | | built_in.range=>_3 | An example for using range | 176 | | built_in.reversed=> | An example for using reversed | 177 | | built_in.round=>_1 | An example for using round | 178 | | built_in.round=>_2 | An example for using round | 179 | | built_in.set=> | An example for using set | 180 | | built_in.setattr=> | An example for using setattr | 181 | | built_in.slice=>_1 | An example for using slice | 182 | | built_in.slice=>_2 | An example for using slice | 183 | | built_in.slice=>_3 | An example for using slice | 184 | | built_in.sorted=>_1 | An example for using sorted | 185 | | built_in.sorted=>_2 | An example for using sorted | 186 | | built_in.sorted=>_3 | An example for using sorted | 187 | | built_in.str=> | An example for using str | 188 | | built_in.sum=>_1 | An example for using sum | 189 | | built_in.sum=>_2 | An example for using sum | 190 | | built_in.tuple=> | An example for using tuple | 191 | | built_in.type=> | An example for using type | 192 | | built_in.vars=> | An example for using vars | 193 | | built_in.zip=>_1 | An example for using zip | 194 | | built_in.zip=>_2                                                 | An example for using zip | 195 | 196 |       197 |       198 | 199 | | string methods code snippets | Description | 200 | | --- | --- | 201 | | .capitalize | Converts the first character to upper case | 202 | | .casefold | Converts string into lower case | 203 | | .center | Returns a centered string | 204 | | .count | Returns the number of times a specified value occurs in a string | 205 | | .encode | Returns an encoded version of the string | 206 | | .endswith | Returns true if the string ends with the specified value | 207 | | .expandtabs | Sets the tab size of the string | 208 | | .find | Searches the string for a specified value and returns the position of where it was found | 209 | | .format | Formats specified values in a string | 210 | | .format_map | Formats specified values in a string | 211 | | .index | Searches the string for a specified value and returns the position of where it was found | 212 | | .isalnum | Returns True if all characters in the string are alphanumeric | 213 | | .isalpha | Returns True if all characters in the string are in the alphabet | 214 | | .isdecimal | Returns True if all characters in the string are decimals | 215 | | .isdigit | Returns True if all characters in the string are digits | 216 | | .isidentifier | Returns True if the string is an identifier | 217 | | .islower | Returns True if all characters in the string are lower case | 218 | | .isnumeric | Returns True if all characters in the string are numeric | 219 | | .isprintable | Returns True if all characters in the string are printable | 220 | | .isspace | Returns True if all characters in the string are whitespaces | 221 | | .istitle | Returns True if the string follows the rules of a title | 222 | | .isupper | Returns True if all characters in the string are upper case | 223 | | .join | Joins the elements of an iterable to the end of the string | 224 | | .ljust | Returns a left justified version of the string | 225 | | .lower | Converts a string into lower case | 226 | | .lstrip | Returns a left trim version of the string | 227 | | .maketrans | Returns a translation table to be used in translations | 228 | | .partition | Returns a tuple where the string is parted into three parts | 229 | | .replace | Returns a string where a specified value is replaced with a specified value | 230 | | .rfind | Searches the string for a specified value and returns the last position of where it was found | 231 | | .rindex | Searches the string for a specified value and returns the last position of where it was found | 232 | | .rpartition | Returns a tuple where the string is parted into three parts | 233 | | .rsplit | Returns a right trim version of the string | 234 | | .split | Splits the string at the specified separator, and returns a list | 235 | | .splitlines | Splits the string at line breaks and returns a list | 236 | | .startswith | Returns true if the string starts with the specified value | 237 | | .swapcase | Swaps cases, lower case becomes upper case and vice versa | 238 | | .title | Converts the first character of each word to upper case | 239 | | .translate | Returns a translated string | 240 | | .upper | Converts a string into upper case | 241 | | .zfill                                                                    | Fills the string with a specified number of 0 values at the beginning | 242 | 243 |       244 |       245 | 246 | 247 | | string methods code examples | Description | 248 | | --- | --- | 249 | | string.capitalize=>_1 | An example for using capitalize | 250 | | string.capitalize=>_2 | An example for using capitalize | 251 | | string.casefold=> | An example for using casefold | 252 | | string.center=>_1 | An example for using center | 253 | | string.center=>_2 | An example for using center | 254 | | string.count=>_1 | An example for using count | 255 | | string.count=>_2 | An example for using count | 256 | | string.encode=> | An example for using encode | 257 | | string.endswith=>_1 | An example for using endswith | 258 | | string.endswith=>_2 | An example for using endswith | 259 | | string.expandtabs=>_1 | An example for using expandtabs | 260 | | string.expandtabs=>_2 | An example for using expandtabs | 261 | | string.find=>_1 | An example for using find | 262 | | string.find=>_2 | An example for using find | 263 | | string.find=>_3 | An example for using find | 264 | | string.find=>_4 | An example for using find | 265 | | string.format=> | An example for using format | 266 | | string.format_map=> | An example for using format_map | 267 | | string.index=>_1 | An example for using index | 268 | | string.index=>_2 | An example for using index | 269 | | string.index=>_3 | An example for using index | 270 | | string.index=>_4 | An example for using index | 271 | | string.isalnum=> | An example for using isalnum | 272 | | string.isalpha=> | An example for using isalpha | 273 | | string.isdecimal=> | An example for using isdecimal | 274 | | string.isdigit=> | An example for using isdigit | 275 | | string.isidentifier=> | An example for using isidentifier | 276 | | string.islower=> | An example for using islower | 277 | | string.isnumeric=> | An example for using isnumeric | 278 | | string.isprintable=> | An example for using isprintable | 279 | | string.isspace=> | An example for using isspace | 280 | | string.istitle=> | An example for using istitle | 281 | | string.isupper=> | An example for using isupper | 282 | | string.join=> | An example for using join | 283 | | string.ljust=> | An example for using ljust | 284 | | string.lower=> | An example for using lower | 285 | | string.lstrip=> | An example for using lstrip | 286 | | string.maketrans=> | An example for using maketrans | 287 | | string.partition=> | An example for using partition | 288 | | string.replace=> | An example for using replace | 289 | | string.rfind=> | An example for using rfind | 290 | | string.rindex=> | An example for using rindex | 291 | | string.rpartition=> | An example for using rpartition | 292 | | string.rsplit=> | An example for using rsplit | 293 | | string.split=> | An example for using split | 294 | | string.splitlines=> | An example for using splitlines | 295 | | string.startswith=> | An example for using startswith | 296 | | string.swapcase=> | An example for using swapcase | 297 | | string.title=> | An example for using title | 298 | | string.translate=> | An example for using translate | 299 | | string.upper=> | An example for using upper | 300 | | string.zfill=>                                                       | An example for using zfill | 301 | 302 | 303 |       304 |       305 | 306 | 307 | 308 | | list methods code snippets | Description | 309 | | --- | --- | 310 | | .append | Adds an element at the end of the list | 311 | | .clear | Removes all the elements from the list | 312 | | .copy | Returns a copy of the list | 313 | | .count | Returns the number of elements with the specified value | 314 | | .extend | Add the elements of a list (or any iterable), to the end of the current list | 315 | | .index | Returns the index of the first element with the specified value | 316 | | .insert | Adds an element at the specified position | 317 | | .pop | Removes the element at the specified position | 318 | | .remove | Removes the first item with the specified value | 319 | | .reverse | Reverses the order of the list | 320 | | .sort                                                                   | Sorts the list | 321 | 322 | 323 |       324 |       325 | 326 | 327 | | list methods code examples | Description | 328 | | --- | --- | 329 | | list.append=> | An example for using append | 330 | | list.clear=> | An example for using clear | 331 | | list.copy=> | An example for using copy | 332 | | list.count=> | An example for using count | 333 | | list.extend=> | An example for using extend | 334 | | list.index=> | An example for using index | 335 | | list.insert=> | An example for using insert | 336 | | list.pop=> | An example for using pop | 337 | | list.remove=> | An example for using remove | 338 | | list.reverse=> | An example for using reverse | 339 | | list.sort=> | An example for using sort | 340 | | list.comp=>_1 | An example for using list comprehension | 341 | | list.comp=>_2 | An example for using list comprehension | 342 | | list.comp=>_3 | An example for using list comprehension | 343 | | list.comp=>_4 | An example for using list comprehension | 344 | | list.comp=>_5                                                 | An example for using list comprehension | 345 | 346 | 347 | 348 | 349 |       350 |       351 | 352 | | sets methods code snippets | Description | 353 | | --- | --- | 354 | | .add | Adds an element to the set | 355 | | .clear | Removes all the elements from the set | 356 | | .copy | Returns a copy of the set | 357 | | .difference | Returns a set containing the difference between two or more sets | 358 | | .difference_update | Removes the items in this set that are also included in another, specified set | 359 | | .discard | Remove the specified item | 360 | | .intersection | Returns a set, that is the intersection of two other sets | 361 | | .intersection_update | Removes the items in this set that are not present in other, specified set(s) | 362 | | .isdisjoint | Returns whether two sets have a intersection or not | 363 | | .issubset | Returns whether another set contains this set or not | 364 | | .issuperset | Returns whether this set contains another set or not | 365 | | .pop | Removes the specified element | 366 | | .remove | Removes the specified element | 367 | | .symmetric_difference | Returns a set with the symmetric differences of two sets | 368 | | .symmetric_difference_update | inserts the symmetric differences from this set and another | 369 | | .union | Return a set containing the union of sets | 370 | | .update                                                           | Update the set with the union of this set and others | 371 | 372 | 373 |       374 |       375 | 376 | | sets methods code examples | Description | 377 | | --- | --- | 378 | | sets.add=> | An example for using add | 379 | | sets.clear=> | An example for using clear | 380 | | sets.copy=> | An example for using copy | 381 | | sets.difference=>_1 | An example for using difference | 382 | | sets.difference=>_2 | An example for using difference | 383 | | sets.difference_update=> | An example for using difference_update | 384 | | sets.discard=> | An example for using discard | 385 | | sets.intersection=>_1 | An example for using intersection | 386 | | sets.intersection=>_2 | An example for using intersection | 387 | | sets.intersection_update=>_1 | An example for using intersection_update | 388 | | sets.intersection_update=>_2 | An example for using intersection_update | 389 | | sets.isdisjoint=>_1 | An example for using isdisjoint | 390 | | sets.isdisjoint=>_2 | An example for using isdisjoint | 391 | | sets.sets.issubset=>_1 | An example for using issubset | 392 | | sets.issubset=>_2 | An example for using issubset | 393 | | sets.issuperset=>_1 | An example for using issuperset | 394 | | sets.issuperset=>_2 | An example for using issuperset | 395 | | sets.pop=> | An example for using pop | 396 | | sets.remove=> | An example for using remove | 397 | | sets.symmetric_difference=> | An example for using symmetric_difference | 398 | | sets.symmetric_difference_update=> | An example for using symmetric_difference_update | 399 | | sets.union=>_1 | An example for using union | 400 | | sets.union=>_2 | An example for using union | 401 | | sets.update=>                                               | An example for using update | 402 | 403 | 404 |       405 |       406 | 407 | | dictionary methods code snippets | Description | 408 | | --- | --- | 409 | | .clear | Removes all the elements from the dictionary | 410 | | .copy | Returns a copy of the dictionary | 411 | | .fromkeys | Returns a dictionary with the specified keys and values | 412 | | .get | Returns the value of the specified key | 413 | | .items | Returns a list containing the a tuple for each key value pair | 414 | | .keys | Returns a list containing the dictionary's keys | 415 | | .pop | Removes the element with the specified key | 416 | | .popitem | Removes the last inserted key-value pai | 417 | | .setdefault | Returns the value of the specified key. If the key does not exist: insert the key, with the specified value | 418 | | .update | Updates the dictionary with the specified key-value pairs | 419 | | .values                                                          | Returns a list of all the values in the dictionary | 420 |       421 |       422 | 423 | | dictionary methods code examples | Description | 424 | | --- | --- | 425 | | dictionary.clear=> | An example for using clear | 426 | | dictionary.copy=> | An example for using copy | 427 | | dictionary.fromkeys=> | An example for using fromkeys | 428 | | dictionary.get=> | An example for using get | 429 | | dictionary.items=> | An example for using items | 430 | | dictionary.keys=> | An example for using keys | 431 | | dictionary.pop=> | An example for using pop | 432 | | dictionary.popitem=> | An example for using popitem | 433 | | dictionary.setdefault=> | An example for using setdefault | 434 | | dictionary.update=> | An example for using update | 435 | | dictionary.values=>                                     | An example for using values | 436 | 437 |       438 |       439 | 440 | 441 | 442 | | tuple methods code snippets | Description | 443 | | --- | --- | 444 | | .count | Returns the number of times a specified value occurs in a tuple | 445 | | .index                                                            | Searches the tuple for a specified value and returns the position of where it was found | 446 |       447 |       448 | 449 | 450 | 451 | | tuple methods code examples | Description | 452 | | --- | --- | 453 | | tuple.count=> | An example for using count | 454 | | tuple.index=>                                             | An example for using index | 455 | 456 | 457 |       458 |       459 | 460 | 461 | | for loop code snippets | Description | 462 | | --- | --- | 463 | | for                                                                 | for Statements | 464 |       465 |       466 | 467 | 468 | | for loop code examples | | 469 | | --- | --- | 470 | | for=> | An example for using for | 471 | | for=>through_a_string | An example for using for | 472 | | for=>break_statement | An example for using for | 473 | | for=>continue_statement | An example for using for | 474 | | for=>range_function_1 | An example for using for | 475 | | for=>range_function_2 | An example for using for | 476 | | for=>range_function_3 | An example for using for | 477 | | for=>for_else | An example for using for | 478 | | for=>for_else                                             | An example for using for | 479 | 480 |       481 |       482 | 483 | 484 | 485 | 486 | | while loop code snippets | Description | 487 | | --- | --- | 488 | | while | while Statements | 489 | | while_else                                                     | while Statements | 490 |       491 |       492 | 493 | | while loop code examples | Description | 494 | | --- | --- | 495 | | while=> | while Statements | 496 | | while=>break_statement | while Statements | 497 | | while=>continue_statement                     | while Statements | 498 | 499 |       500 |       501 | 502 | | if/else statement code snippets | Description | 503 | | --- | --- | 504 | | if | if Statements | 505 | | ifelif | if/else if Statements | 506 | | ifelifelse | if/else if/else Statements | 507 | | ifelse | if/else Statements | 508 | | ifshort | ifshort Statements | 509 | | else                                                             | else Statements | 510 | 511 |       512 |       513 | 514 | | class code snippets | Description | 515 | | --- | --- | 516 | | class=> | python class | 517 | | __init__=> | class __init__ method | 518 | | __iter__=> | class __iter__ method | 519 | | __next__=>                                                       | class __next__ method | 520 |       521 |       522 | 523 | | class code examples | Description | 524 | | --- | --- | 525 | | class=>_1 | oop inheritance example | 526 | | class=>inheritance_1 | oop inheritance example | 527 | | class=>inheritance_2 | oop inheritance example | 528 | | class=>with_attribute_1 | class with attribute example | 529 | | class=>with_attribute_2 | class with attribute example | 530 | | class=>with_attribute_3 | class with attribute example | 531 | | class=>with_method_1 | class with method example | 532 | | class=>with_method_2 | class with method example | 533 | | class=>encapsulation | class encapsulation example | 534 | | class=>polymorphism                             | class polymorphism example | 535 | 536 |       537 |       538 | 539 | 540 | 541 | | import code snippets | Description | 542 | | --- | --- | 543 | | import=>                                                   | import module | 544 | 545 |       546 |       547 | 548 | 549 | | List Comprehensions code snippets | Description | 550 | | --- | --- | 551 | | comp=>                                                 |List Comprehensions | 552 | 553 | 554 |       555 |       556 | 557 | | List Comprehensions code examples | Description | 558 | | --- | --- | 559 | | list.comp=>_1 | An example for using list comprehension | 560 | | list.comp=>_2 | An example for using list comprehension | 561 | | list.comp=>_3 | An example for using list comprehension | 562 | | list.comp=>_4 | An example for using list comprehension | 563 | | list.comp=>_5 | An example for using list comprehension | 564 | 565 | 566 | 567 |       568 |       569 | 570 | | lambda code examples | Description | 571 | | --- | --- | 572 | | lambda                                                  | A lambda function can take any number of arguments, but can only have one expression.| 573 | 574 |       575 |       576 | 577 | | function code snippets | Description | 578 | | --- | --- | 579 | | def=> | Defining Function | 580 | | def=>with_default_value | Defining Function wqith default values | 581 | | function=>                                           | Defining Function | 582 | 583 | 584 |       585 |       586 | 587 | | file code examples | Description | 588 | | --- | --- | 589 | | file=>openFile | open a file | 590 | | file=>openFileReadLine | Read one line of the file | 591 | | file=>writeExistFile | Write to an Existing File | 592 | | file=>writeOwerWrite | Open a file and overwrite the content | 593 | | file=>createFileIfDoesNotExist | Create a new file if it does not exist | 594 | | file=>createFile | Create a new file | 595 | | file=>deleteFile                                     | delete a file | 596 | 597 | 598 |       599 |       600 | 601 | 602 | 603 | ### For example 604 | 605 | Creating a class 606 | 607 | class=>with_attribute_1 608 | 609 | ``` 610 | class Parrot: 611 | 612 | # class attribute 613 | species = 'bird' 614 | 615 | # instance attribute 616 | def __init__(self, name, age): 617 | self.name = name 618 | self.age = age 619 | 620 | # instantiate the Parrot class 621 | blu = Parrot('Blu', 10) 622 | woo = Parrot('woo', 15) 623 | 624 | # access the class attributes 625 | print('Blu is a {}'.format(blu.__class__.species)) 626 | print('Woo is also a {}'.format(woo.__class__.species)) 627 | # access the instance attributes 628 | print('{} is {} years old'.format( blu.name, blu.age)) 629 | print('{} is {} years old'.format( woo.name, woo.age)) 630 | 631 | ``` 632 | 633 |       634 |       635 | 636 | 637 | ## Release Notes 638 | 639 | Users appreciate release notes as you update your extension. 640 | 641 | ### For more information 642 | 643 | * [python documentation](https://docs.python.org/3/tutorial/index.html) 644 | * [w3schools](https://www.w3schools.com/python/default.asp) 645 | * [www.programiz](https://www.programiz.com/python-programming) 646 | * [python.swaroopch](https://python.swaroopch.com/oop.html) 647 | * [pythonforbeginners](https://www.pythonforbeginners.com/basics/list-comprehensions-in-python) 648 | 649 | 650 | **Enjoy!** 651 | 652 | ### 1.0.0 653 | 654 | Initial release of python code snippets 655 | 656 | ### 1.0.2 657 | 658 | Updated README.md 659 | 660 | 661 | ----------------------------------------------------------------------------------------------------------- 662 | 663 | 664 | 665 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ylcnfrht/vscode-python-snippet-pack/7fa16e40449c3edac77e9fabf66ae53658949ee6/icon.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pythonsnippets", 3 | "displayName": "python snippets", 4 | "description": "Code snippets for python", 5 | "version": "1.0.2", 6 | "publisher": "frhtylcn", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/ylcnfrht/vscode-python-snippet-pack" 10 | }, 11 | "icon": "icon.png", 12 | "engines": { 13 | "vscode": "^1.28.0" 14 | }, 15 | "categories": [ 16 | "Snippets" 17 | ], 18 | "contributes": { 19 | "snippets": [{ 20 | "language": "python", 21 | "path": "./snippets/python_snippets.json" 22 | }] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /python.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ylcnfrht/vscode-python-snippet-pack/7fa16e40449c3edac77e9fabf66ae53658949ee6/python.gif -------------------------------------------------------------------------------- /snippets/python_snippets.json: -------------------------------------------------------------------------------- 1 | { 2 | "abs": { 3 | "prefix": "abs", 4 | "body": "abs(x)", 5 | "description": "Returns the absolute value of a number" 6 | }, 7 | "built_in.abs=>int": { 8 | "prefix": "built_in.abs=>int", 9 | "body": [ 10 | "x = abs(-7.25)", 11 | "print(x)" 12 | ], 13 | "description": "An example for using abs method" 14 | }, 15 | "built_in.abs=>float": { 16 | "prefix": "built_in.abs=>float", 17 | "body": [ 18 | "x = abs(-20)", 19 | "print(x)" 20 | ], 21 | "description": "An example for using abs method" 22 | }, 23 | "built_in.abs=>complex": { 24 | "prefix": "built_in.abs=>complex", 25 | "body": [ 26 | "x = abs((3 - 4j))", 27 | "print(x)" 28 | ], 29 | "description": "An example for using abs method" 30 | }, 31 | "all": { 32 | "prefix": "all", 33 | "body": "all(iterable)", 34 | "description": "Returns True if all items in an iterable object are true" 35 | }, 36 | "built_in.all=>list_1": { 37 | "prefix": "built_in.all=>list_1", 38 | "body": [ 39 | "mylist = [True, True, True]", 40 | "x = all(mylist)", 41 | "print(x)", 42 | "", 43 | "# Return True" 44 | ], 45 | "description": "An example for using all with list" 46 | }, 47 | "built_in.all=>list_2": { 48 | "prefix": "built_in.all=>list_2", 49 | "body": [ 50 | "mylist = [0, 1, 1]", 51 | "x = all(mylist)", 52 | "print(x)", 53 | "", 54 | "# Returns False because 0 is the same as False" 55 | ], 56 | "description": "An example for using all with list" 57 | }, 58 | "built_in.all=>tuple": { 59 | "prefix": "built_in.all=>tuple", 60 | "body": [ 61 | "mytuple = (0, True, False)", 62 | "x = all(mytuple)", 63 | "print(x)", 64 | "", 65 | "# Returns False because both the first and the third items are False" 66 | ], 67 | "description": "An example for using all with tuple" 68 | }, 69 | "built_in.all=>set": { 70 | "prefix": "built_in.all=>set", 71 | "body": [ 72 | "myset = {0, 1, 0}", 73 | "x = all(myset)", 74 | "print(x)", 75 | "", 76 | "# Returns False because both the first and the third items are False" 77 | ], 78 | "description": "An example for using all with set" 79 | }, 80 | "built_in.all=>dictionary": { 81 | "prefix": "built_in.all=>dictionary", 82 | "body": [ 83 | "mydict = {0 : 'Apple', 1 : 'Orange'}", 84 | "x = all(mydict)", 85 | "print(x)", 86 | "", 87 | "# Returns False because the first key is false.", 88 | "# For dictionaries the all() function checks the keys, not the values." 89 | ], 90 | "description": "An example for using all with dictionary" 91 | }, 92 | "any": { 93 | "prefix": "any", 94 | "body": "any(iterable)", 95 | "description": "Returns True if any item in an iterable object is true" 96 | }, 97 | "built_in.any=>list_1": { 98 | "prefix": "built_in.any=>list_1", 99 | "body": [ 100 | "mylist = [False, True, False]", 101 | "x = any(mylist)", 102 | "print(x)", 103 | "", 104 | "# Return True" 105 | ], 106 | "description": "An example for using all with list" 107 | }, 108 | "ascii": { 109 | "prefix": "ascii", 110 | "body": "ascii(object)", 111 | "description": "Returns a readable version of an object. Replaces none-ascii characters with escape character" 112 | }, 113 | "built_in.ascii=>_1": { 114 | "prefix": "built_in.ascii=>_list_1", 115 | "body": [ 116 | "x = ascii('My name is Ståle')", 117 | "print(x)" 118 | ], 119 | "description": "An example for using ascii" 120 | }, 121 | "bin": { 122 | "prefix": "bin", 123 | "body": "bin(x)", 124 | "description": "Returns the binary version of a number" 125 | }, 126 | "built_in.bin=>_1": { 127 | "prefix": "built_in.bin=>_1", 128 | "body": [ 129 | "x = bin(36)", 130 | "print(x)", 131 | "# Result : 0b100100" 132 | ], 133 | "description": "An example for using ascii" 134 | }, 135 | "bool": { 136 | "prefix": "bool", 137 | "body": "bool(object)", 138 | "description": "Returns the boolean value of the specified object" 139 | }, 140 | "built_in.bool=>_1": { 141 | "prefix": "built_in.bool=>_1", 142 | "body": [ 143 | "x = bool(1)", 144 | "print(x)", 145 | "# Result : True" 146 | ], 147 | "description": "An example for using bool" 148 | }, 149 | "bytearray": { 150 | "prefix": "bytearray", 151 | "body": "bytearray([source[, encoding[, errors]]])", 152 | "description": "Returns an array of bytes" 153 | }, 154 | "built_in.bytearray=>_1": { 155 | "prefix": "built_in.bytearray=>_1", 156 | "body": [ 157 | "x = bytearray(4)", 158 | "print(x)" 159 | ], 160 | "description": "An example for using bool" 161 | }, 162 | "bytes": { 163 | "prefix": "bytes", 164 | "body": "bytes(x, encoding, error)", 165 | "description": "Returns a bytes object" 166 | }, 167 | "built_in.bytes=>_1": { 168 | "prefix": "built_in.bytes=>_1", 169 | "body": [ 170 | "x = x = bytes(4)", 171 | "print(x)" 172 | ], 173 | "description": "An example for using bytes" 174 | }, 175 | "callable": { 176 | "prefix": "callable", 177 | "body": "callable(object)", 178 | "description": "Returns True if the specified object is callable, otherwise False" 179 | }, 180 | "built_in.callable=>_1": { 181 | "prefix": "built_in.callable=>_1", 182 | "body": [ 183 | "def x():", 184 | "a = 5", 185 | "", 186 | "print(callable(x))" 187 | ], 188 | "description": "An example for using callable" 189 | }, 190 | "built_in.callable=>_2": { 191 | "prefix": "built_in.callable=>_2", 192 | "body": [ 193 | "x = 5", 194 | "", 195 | "print(callable(x))" 196 | ], 197 | "description": "An example for using bytes" 198 | }, 199 | "chr": { 200 | "prefix": "chr", 201 | "body": "chr(i)", 202 | "description": "Returns a character from the specified Unicode code." 203 | }, 204 | "built_in.chr=>_1": { 205 | "prefix": "built_in.chr=>_1", 206 | "body": [ 207 | "x = chr(97)", 208 | "", 209 | "print(x)" 210 | ], 211 | "description": "An example for using bytes" 212 | }, 213 | "classmethod": { 214 | "prefix": "classmethod", 215 | "body": "classmethod(function)", 216 | "description": "Converts a method into a class method" 217 | }, 218 | "compile": { 219 | "prefix": "compile", 220 | "body": "compile(source, filename, mode, flag, dont_inherit, optimize)", 221 | "description": "Returns the specified source as an object, ready to be executed" 222 | }, 223 | "built_in.compile=>_1": { 224 | "prefix": "built_in.compile=>_1", 225 | "body": [ 226 | "mytext = 'print(55)'", 227 | "x = compile('mytext', 'test', 'eval')", 228 | "exec(x)" 229 | ], 230 | "description": "An example for using compile" 231 | }, 232 | "built_in.compile=>_2": { 233 | "prefix": "built_in.compile=>_1", 234 | "body": [ 235 | "mytext = 'print(55)\nprint(88)'", 236 | "x = compile('mytext', 'test', 'exec')", 237 | "exec(x)" 238 | ], 239 | "description": "An example for using compile" 240 | }, 241 | "complex": { 242 | "prefix": "complex", 243 | "body": "complex(real, imaginary)", 244 | "description": "Returns a complex number" 245 | }, 246 | "built_in.complex=>_1": { 247 | "prefix": "built_in.complex=>_1", 248 | "body": [ 249 | "x = complex(3, 5)", 250 | "print(x)" 251 | ], 252 | "description": "An example for using complex" 253 | }, 254 | "built_in.complex=>_2": { 255 | "prefix": "built_in.complex=>_2", 256 | "body": [ 257 | "x = complex('3+5j')", 258 | "print(x)" 259 | ], 260 | "description": "An example for using complex" 261 | }, 262 | "delattr": { 263 | "prefix": "delattr", 264 | "body": "delattr(object, attribute)", 265 | "description": "Deletes the specified attribute (property or method) from the specified object" 266 | }, 267 | "built_in.delattr=>_1": { 268 | "prefix": "built_in.delattr=>_1", 269 | "body": [ 270 | "class Person:", 271 | " name = 'John'", 272 | " age = 36", 273 | " country = 'Norway'", 274 | "", 275 | "delattr(Person, 'age')", 276 | "# The Person object will no longer contain an age property" 277 | ], 278 | "description": "An example for using delattr" 279 | }, 280 | "dict": { 281 | "prefix": "dict", 282 | "body": "dict(keyword arguments)", 283 | "description": "Returns a dictionary (Array)" 284 | }, 285 | "built_in.dict=>_1": { 286 | "prefix": "built_in.dict=>_1", 287 | "body": [ 288 | "x = dict(name = 'John', age = 36, country = 'Norway')", 289 | "print(x)" 290 | ], 291 | "description": "An example for using dict" 292 | }, 293 | "dir": { 294 | "prefix": "dir", 295 | "body": "dir(object)", 296 | "description": "Returns a list of the specified object's properties and methods" 297 | }, 298 | "built_in.dir=>": { 299 | "prefix": "built_in.dir=>", 300 | "body": [ 301 | "class Person:", 302 | " name = 'John'", 303 | " age = 36", 304 | " country = 'Norway'", 305 | "print(dir(Person))" 306 | ], 307 | "description": "An example for using dict" 308 | }, 309 | "divmod": { 310 | "prefix": "divmod", 311 | "body": "divmod(divident, divisor)", 312 | "description": "Returns the quotient and the remainder when argument1 is divided by argument2" 313 | }, 314 | "built_in.divmod=>_1": { 315 | "prefix": "built_in.divmod=>_1", 316 | "body": [ 317 | "x = divmod(5, 2)", 318 | "print(x)" 319 | ], 320 | "description": "An example for using divmod" 321 | }, 322 | "enumerate": { 323 | "prefix": "enumerate", 324 | "body": "enumerate(iterable, start)", 325 | "description": "Takes a collection (e.g. a tuple) and returns it as an enumerate object" 326 | }, 327 | "built_in.enumerate=>_1": { 328 | "prefix": "built_in.enumerate=>_1", 329 | "body": [ 330 | "x = ('apple', 'banana', 'cherry')", 331 | "y = enumerate(x)", 332 | "", 333 | "print(list(y))" 334 | ], 335 | "description": "An example for using enumerate" 336 | }, 337 | "eval": { 338 | "prefix": "eval", 339 | "body": "eval(expression, globals, locals)", 340 | "description": "Evaluates and executes an expression" 341 | }, 342 | "built_in.eval=>_1": { 343 | "prefix": "built_in.eval=>_1", 344 | "body": [ 345 | "x = 'print(55)'", 346 | "eval(x)" 347 | ], 348 | "description": "An example for using eval" 349 | }, 350 | "exec": { 351 | "prefix": "exec", 352 | "body": "exec(object, globals, locals)", 353 | "description": "Executes the specified code (or object)" 354 | }, 355 | "built_in.exec=>_1": { 356 | "prefix": "built_in.exec=>_1", 357 | "body": [ 358 | "x = 'age = 25\nprint(age)'", 359 | "exec(x)" 360 | ], 361 | "description": "An example for using exec" 362 | }, 363 | "filter": { 364 | "prefix": "filter", 365 | "body": "filter(function, iterable)", 366 | "description": "Use a filter function to exclude items in an iterable object" 367 | }, 368 | "built_in.filter=>_1": { 369 | "prefix": "built_in.filter=>_1", 370 | "body": [ 371 | "ages = [5, 12, 17, 18, 24, 32]", 372 | "", 373 | "def myFunc(x):", 374 | " if x < 18:", 375 | " return False", 376 | " else:", 377 | " return True", 378 | "", 379 | "adults = filter(myFunc, ages)", 380 | "", 381 | "for x in adults:", 382 | " print(x)" 383 | ], 384 | "description": "An example for using filter" 385 | }, 386 | "float": { 387 | "prefix": "float", 388 | "body": "float(value)", 389 | "description": "Returns a floating point number" 390 | }, 391 | "built_in.float=>_1": { 392 | "prefix": "built_in.float=>_1", 393 | "body": [ 394 | "x = float(3)", 395 | "print(x)" 396 | ], 397 | "description": "An example for using float" 398 | }, 399 | "built_in.float=>_2": { 400 | "prefix": "built_in.float=>_2", 401 | "body": [ 402 | "x = float('3.500')", 403 | "print(x)" 404 | ], 405 | "description": "An example for using float" 406 | }, 407 | "format": { 408 | "prefix": "format", 409 | "body": "format(value, format)", 410 | "description": "Formats a specified value" 411 | }, 412 | "built_in.format=>_1": { 413 | "prefix": "built_in.format=>_1", 414 | "body": [ 415 | "x = format(0.5, '%')", 416 | "print(x)" 417 | ], 418 | "description": "An example for using format" 419 | }, 420 | "built_in.format=>_1": { 421 | "prefix": "built_in.format=>_1", 422 | "body": [ 423 | "x = format(255, 'x')", 424 | "print(x)" 425 | ], 426 | "description": "An example for using format" 427 | }, 428 | "frozenset": { 429 | "prefix": "frozenset", 430 | "body": "frozenset(iterable)", 431 | "description": "Returns a frozenset object" 432 | }, 433 | "built_in.frozenset=>_1": { 434 | "prefix": "built_in.frozenset=>_1", 435 | "body": [ 436 | "mylist = ['apple', 'banana', 'cherry']", 437 | "x = frozenset(mylist)", 438 | "print(x)" 439 | ], 440 | "description": "An example for using frozenset" 441 | }, 442 | "built_in.frozenset=>_2": { 443 | "prefix": "built_in.frozenset=>_2", 444 | "body": [ 445 | "mylist = ['apple', 'banana', 'cherry']", 446 | "x = frozenset(mylist)", 447 | "x[1] = 'strawberry'", 448 | "print(x)" 449 | ], 450 | "description": "An example for using frozenset" 451 | }, 452 | "getattr": { 453 | "prefix": "getattr", 454 | "body": "getattr(object, attribute, default)", 455 | "description": "Returns the value of the specified attribute (property or method)" 456 | }, 457 | "built_in.frozenset=>_3": { 458 | "prefix": "built_in.frozenset=>_3", 459 | "body": [ 460 | "class Person:", 461 | " name = 'John'", 462 | " age = 36", 463 | " country = 'Norway'", 464 | "", 465 | "x = getattr(Person, 'age')", 466 | "", 467 | "print(x)" 468 | ], 469 | "description": "An example for using frozenset" 470 | }, 471 | "globals": { 472 | "prefix": "globals", 473 | "body": "globals()", 474 | "description": "Returns the current global symbol table as a dictionary" 475 | }, 476 | "built_in.globals=>_1": { 477 | "prefix": "built_in.globals=>_1", 478 | "body": [ 479 | "x = globals()", 480 | "print(x)" 481 | ], 482 | "description": "An example for using globals" 483 | }, 484 | "built_in.globals=>_2": { 485 | "prefix": "built_in.globals=>_2", 486 | "body": [ 487 | "x = globals()", 488 | "print(x['__file__'])" 489 | ], 490 | "description": "An example for using globals" 491 | }, 492 | "hasattr": { 493 | "prefix": "hasattr", 494 | "body": "hasattr(object, attribute)", 495 | "description": "Returns True if the specified object has the specified attribute (property/method)" 496 | }, 497 | "built_in.hasattr=>": { 498 | "prefix": "built_in.hasattr=>", 499 | "body": [ 500 | "class Person:", 501 | " name = 'John'", 502 | " age = 36", 503 | " country = 'Norway'", 504 | "", 505 | "x = hasattr(Person, 'age')", 506 | "", 507 | "print(x)" 508 | ], 509 | "description": "An example for using hasattr" 510 | }, 511 | "hash": { 512 | "prefix": "hash", 513 | "body": "hash(object)", 514 | "description": "Returns the hash value of a specified object" 515 | }, 516 | "help": { 517 | "prefix": "help", 518 | "body": "help(object)", 519 | "description": "Executes the built-in help system" 520 | }, 521 | "hex": { 522 | "prefix": "hex", 523 | "body": "hex(number)", 524 | "description": "Converts a number into a hexadecimal value" 525 | }, 526 | "built_in.hex=>": { 527 | "prefix": "built_in.hex=>", 528 | "body": [ 529 | "x = hex(255)", 530 | "print(x)" 531 | ], 532 | "description": "An example for using hasattr" 533 | }, 534 | "int": { 535 | "prefix": "int", 536 | "body": "int(value, base)", 537 | "description": "Returns an integer number" 538 | }, 539 | "built_in.int=>_1": { 540 | "prefix": "built_in.int=>_1", 541 | "body": [ 542 | "x = int(3.5)", 543 | "print(x)" 544 | ], 545 | "description": "An example for using int" 546 | }, 547 | "built_in.int=>_2": { 548 | "prefix": "built_in.int=>_2", 549 | "body": [ 550 | "x = int('12')", 551 | "print(x)" 552 | ], 553 | "description": "An example for using int" 554 | }, 555 | "id": { 556 | "prefix": "id", 557 | "body": "id(object)", 558 | "description": "Returns the id of an object" 559 | }, 560 | "built_in.id=>": { 561 | "prefix": "built_in.id=>", 562 | "body": [ 563 | "class Foo:", 564 | "b = 5", 565 | "", 566 | "dummyFoo = Foo()", 567 | "print('id of dummyFoo =',id(dummyFoo))" 568 | ], 569 | "description": "An example for using id" 570 | }, 571 | "input": { 572 | "prefix": "input", 573 | "body": "input(prompt)", 574 | "description": "Allowing user input" 575 | }, 576 | "built_in.input=>_1": { 577 | "prefix": "built_in.input=>_1", 578 | "body": [ 579 | "x = input('Enter your name:')", 580 | "print('Hello, ' + x)" 581 | ], 582 | "description": "An example for using input" 583 | }, 584 | "built_in.input=>_2": { 585 | "prefix": "built_in.input=>_2", 586 | "body": [ 587 | "print('Enter your name:')", 588 | "x = input()", 589 | "print('Hello, ' + x)" 590 | ], 591 | "description": "An example for using input" 592 | }, 593 | "isinstance": { 594 | "prefix": "isinstance", 595 | "body": "isinstance(object, type)", 596 | "description": "Returns True if a specified object is an instance of a specified object" 597 | }, 598 | "built_in.isinstance=>_1": { 599 | "prefix": "built_in.isinstance=>_1", 600 | "body": [ 601 | "x = isinstance(5, int)", 602 | "", 603 | "print(x)" 604 | ], 605 | "description": "An example for using isinstance" 606 | }, 607 | "built_in.isinstance=>_2": { 608 | "prefix": "built_in.isinstance=>_2", 609 | "body": [ 610 | "x = isinstance('Hello', (float, int, str, list, dict, tuple))", 611 | "", 612 | "print(x)" 613 | ], 614 | "description": "An example for using isinstance" 615 | }, 616 | "built_in.isinstance=>_3": { 617 | "prefix": "built_in.isinstance=>_3", 618 | "body": [ 619 | "class myObj:", 620 | " name = 'John'", 621 | "", 622 | "y = myObj()", 623 | "", 624 | "x = isinstance(y, myObj)", 625 | "print(x)" 626 | ], 627 | "description": "An example for using isinstance" 628 | }, 629 | "issubclass": { 630 | "prefix": "issubclass", 631 | "body": "issubclass(object, subclass)", 632 | "description": "Returns True if a specified class is a subclass of a specified object" 633 | }, 634 | "built_in.issubclass=>": { 635 | "prefix": "built_in.issubclass=>", 636 | "body": [ 637 | "class myAge:", 638 | " age = 36", 639 | "", 640 | "class myObj(myAge):", 641 | " name = 'John'", 642 | " age = myAge", 643 | "", 644 | " x = issubclass(myObj, myAge)", 645 | "", 646 | "print(x)" 647 | ], 648 | "description": "An example for using isinstance" 649 | }, 650 | "iter": { 651 | "prefix": "iter", 652 | "body": "iter(object, subclass)", 653 | "description": "Returns an iterator object" 654 | }, 655 | "built_in.iter=>": { 656 | "prefix": "built_in.iter=>", 657 | "body": [ 658 | "x = iter(['apple', 'banana', 'cherry'])", 659 | "print(next(x))", 660 | "print(next(x))", 661 | "print(next(x))" 662 | ], 663 | "description": "An example for using iter" 664 | }, 665 | "len": { 666 | "prefix": "len", 667 | "body": "len(s)", 668 | "description": "Returns the length of an object" 669 | }, 670 | "built_in.len=>_1": { 671 | "prefix": "built_in.len=>_1", 672 | "body": [ 673 | "mylist = ['apple', 'banana', 'cherry']", 674 | "x = len(mylist)" 675 | ], 676 | "description": "An example for using len" 677 | }, 678 | "built_in.len=>_2": { 679 | "prefix": "built_in.len=>_2", 680 | "body": [ 681 | "mylist = 'Hello'", 682 | "x = len(mylist)" 683 | ], 684 | "description": "An example for using len" 685 | }, 686 | "list": { 687 | "prefix": "list", 688 | "body": "list([iterable])", 689 | "description": "Returns a list" 690 | }, 691 | "built_in.list=>": { 692 | "prefix": "built_in.list=>", 693 | "body": [ 694 | "x = list(('apple', 'banana', 'cherry'))", 695 | "print(x)" 696 | ], 697 | "description": "An example for using list" 698 | }, 699 | "locals": { 700 | "prefix": "locals", 701 | "body": "locals()", 702 | "description": "Returns an updated dictionary of the current local symbol table" 703 | }, 704 | "built_in.locals=>_1": { 705 | "prefix": "built_in.locals=>_1", 706 | "body": [ 707 | "x = locals()", 708 | "print(x)" 709 | ], 710 | "description": "An example for using locals" 711 | }, 712 | "built_in.locals=>_2": { 713 | "prefix": "built_in.locals=>_2", 714 | "body": [ 715 | "x = locals()", 716 | "print(x['__file__'])" 717 | ], 718 | "description": "An example for using locals" 719 | }, 720 | "map": { 721 | "prefix": "map", 722 | "body": "map(function, iterables)", 723 | "description": "Returns the specified iterator with the specified function applied to each item" 724 | }, 725 | "built_in.map=>_1": { 726 | "prefix": "built_in.map=>_1", 727 | "body": [ 728 | "def myfunc(n):", 729 | " return len(n)", 730 | "", 731 | "x = map(myfunc, ('apple', 'banana', 'cherry'))", 732 | "", 733 | "print(x)" 734 | ], 735 | "description": "An example for using map" 736 | }, 737 | "built_in.map=>_2": { 738 | "prefix": "built_in.map=>_2", 739 | "body": [ 740 | "def myfunc(a, b):", 741 | " return a + b", 742 | "", 743 | "x = map(myfunc, ('apple', 'banana', 'cherry'), ('orange', 'lemon', 'pineapple'))", 744 | "", 745 | "print(x)" 746 | ], 747 | "description": "An example for using map" 748 | }, 749 | "max": { 750 | "prefix": "max", 751 | "body": "max(iterable)", 752 | "description": "Returns the largest item in an iterable" 753 | }, 754 | "built_in.max=>_1": { 755 | "prefix": "built_in.max=>_1", 756 | "body": [ 757 | "x = max(5, 10)", 758 | "print(x)" 759 | ], 760 | "description": "An example for using max" 761 | }, 762 | "built_in.max=>_2": { 763 | "prefix": "built_in.max=>_2", 764 | "body": [ 765 | "x = max('Mike', 'John', 'Vicky')", 766 | "print(x)" 767 | ], 768 | "description": "An example for using max" 769 | }, 770 | "built_in.max=>_3": { 771 | "prefix": "built_in.max=>_3", 772 | "body": [ 773 | "a = (1, 5, 3, 9)", 774 | "x = max(a)", 775 | "print(x)" 776 | ], 777 | "description": "An example for using max" 778 | }, 779 | "memoryview": { 780 | "prefix": "memoryview", 781 | "body": "memoryview(obj)", 782 | "description": "Returns a memory view object" 783 | }, 784 | "built_in.memoryview=>": { 785 | "prefix": "built_in.memoryview=>", 786 | "body": [ 787 | "x = memoryview(b'Hello')", 788 | "print(x)", 789 | "", 790 | "#return the Unicode of the first character", 791 | "print(x[0])", 792 | "", 793 | "#return the Unicode of the second character", 794 | "print(x[1])" 795 | ], 796 | "description": "An example for using memoryview" 797 | }, 798 | "min": { 799 | "prefix": "min", 800 | "body": "min(iterable)", 801 | "description": "Returns the smallest item in an iterable" 802 | }, 803 | "built_in.min=>_1": { 804 | "prefix": "built_in.min=>_1", 805 | "body": [ 806 | "x = min(5, 10)", 807 | "print(x)" 808 | ], 809 | "description": "An example for using min" 810 | }, 811 | "built_in.min=>_2": { 812 | "prefix": "built_in.min=>_2", 813 | "body": [ 814 | "x = min('Mike', 'John', 'Vicky')", 815 | "print(x)" 816 | ], 817 | "description": "An example for using min" 818 | }, 819 | "built_in.min=>_3": { 820 | "prefix": "built_in.min=>_3", 821 | "body": [ 822 | "a = (1, 5, 3, 9)", 823 | "x = min(a)", 824 | "print(x)" 825 | ], 826 | "description": "An example for using min" 827 | }, 828 | "next": { 829 | "prefix": "next", 830 | "body": "next(iterable, default)", 831 | "description": "Returns the next item in an iterable" 832 | }, 833 | "built_in.next=>_1": { 834 | "prefix": "built_in.next=>_1", 835 | "body": [ 836 | "mylist = iter(['apple', 'banana', 'cherry'])", 837 | "x = next(mylist)", 838 | "print(x)", 839 | "x = next(mylist)", 840 | "print(x)", 841 | "x = next(mylist)", 842 | "print(x)" 843 | ], 844 | "description": "An example for using next" 845 | }, 846 | "built_in.next=>_2": { 847 | "prefix": "built_in.next=>_2", 848 | "body": [ 849 | "mylist = iter(['apple', 'banana', 'cherry'])", 850 | "x = next(mylist, 'orange')", 851 | "print(x)", 852 | "x = next(mylist, 'orange')", 853 | "print(x)", 854 | "x = next(mylist, 'orange')", 855 | "print(x)", 856 | "x = next(mylist, 'orange')", 857 | "print(x)" 858 | ], 859 | "description": "An example for using next" 860 | }, 861 | "object": { 862 | "prefix": "object", 863 | "body": "object()", 864 | "description": "Returns a new object" 865 | }, 866 | "built_in.object=>": { 867 | "prefix": "built_in.object=>", 868 | "body": [ 869 | "x = object()", 870 | "print(dir(x))" 871 | ], 872 | "description": "An example for using object" 873 | }, 874 | "oct": { 875 | "prefix": "oct", 876 | "body": "oct(x)", 877 | "description": "Converts a number into an octal" 878 | }, 879 | "built_in.oct=>": { 880 | "prefix": "built_in.oct=>", 881 | "body": [ 882 | "x = oct(12)", 883 | "print(x)" 884 | ], 885 | "description": "An example for using oct" 886 | }, 887 | "open": { 888 | "prefix": "open", 889 | "body": "open(file, mode)", 890 | "description": "Opens a file and returns a file object" 891 | }, 892 | "built_in.open=>": { 893 | "prefix": "built_in.open=>", 894 | "body": [ 895 | "f = open('demofile.txt', 'r')", 896 | "print(f.read())" 897 | ], 898 | "description": "An example for using open" 899 | }, 900 | "ord": { 901 | "prefix": "ord", 902 | "body": "ord(c)", 903 | "description": "Given 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." 904 | }, 905 | "built_in.ord=>": { 906 | "prefix": "built_in.ord=>", 907 | "body": [ 908 | "x=ord('a')", 909 | "print(x)" 910 | ], 911 | "description": "An example for using ord" 912 | }, 913 | "pow": { 914 | "prefix": "pow", 915 | "body": "pow(x, y)", 916 | "description": "Return x to the power y" 917 | }, 918 | "built_in.pow=>": { 919 | "prefix": "built_in.pow=>", 920 | "body": [ 921 | "x=pow(2,5)", 922 | "print(x)" 923 | ], 924 | "description": "An example for using pow" 925 | }, 926 | "print": { 927 | "prefix": "print", 928 | "body": "print(object(s), separator=separator, end=end, file=file, flush=flush)", 929 | "description": "Prints to the standard output device" 930 | }, 931 | "built_in.print=>_1": { 932 | "prefix": "built_in.print=>_1", 933 | "body": [ 934 | "print('Hello', 'how are you?')" 935 | ], 936 | "description": "An example for using print" 937 | }, 938 | "built_in.print=>_2": { 939 | "prefix": "built_in.print=>_2", 940 | "body": [ 941 | "x = ('apple', 'banana', 'cherry')", 942 | "print(x)" 943 | ], 944 | "description": "An example for using print" 945 | }, 946 | "built_in.print=>_3": { 947 | "prefix": "built_in.print=>_3", 948 | "body": [ 949 | "print('Hello', 'how are you?', sep=' ---')" 950 | ], 951 | "description": "An example for using print" 952 | }, 953 | "property": { 954 | "prefix": "property", 955 | "body": "property(fget=None, fset=None, fdel=None, doc=None)", 956 | "description": "Gets, sets, deletes a property" 957 | }, 958 | "built_in.property=>": { 959 | "prefix": "built_in.property=>", 960 | "body": [ 961 | "class C:", 962 | " def __init__(self):", 963 | " self._x = None", 964 | " def getx(self):", 965 | " return self._x", 966 | " def setx(self, value):", 967 | " self._x = value", 968 | " def delx(self):", 969 | " del self._x", 970 | " x = property(getx, setx, delx, 'I'm the 'x' property.')" 971 | ], 972 | "description": "An example for using property" 973 | }, 974 | "range": { 975 | "prefix": "range", 976 | "body": "range(start, stop, step)", 977 | "description": "Returns a sequence of numbers, starting from 0 and increments by 1 (by default)" 978 | }, 979 | "built_in.range=>_1": { 980 | "prefix": "built_in.range=>_1", 981 | "body": [ 982 | "x = range(6)", 983 | "for n in x:", 984 | " print(n)" 985 | ], 986 | "description": "An example for using range" 987 | }, 988 | "built_in.range=>_2": { 989 | "prefix": "built_in.range=>_2", 990 | "body": [ 991 | "x = range(3, 6)", 992 | "for n in x:", 993 | " print(n)" 994 | ], 995 | "description": "An example for using range" 996 | }, 997 | "built_in.range=>_3": { 998 | "prefix": "built_in.range=>_3", 999 | "body": [ 1000 | "x = range(3, 20, 2)", 1001 | "for n in x:", 1002 | " print(n)" 1003 | ], 1004 | "description": "An example for using range" 1005 | }, 1006 | "repr": { 1007 | "prefix": "repr", 1008 | "body": "repr(object)", 1009 | "description": "Returns a readable version of an object" 1010 | }, 1011 | "reversed": { 1012 | "prefix": "reversed", 1013 | "body": "reversed(seq)", 1014 | "description": "Returns a reversed iterator" 1015 | }, 1016 | "built_in.reversed=>": { 1017 | "prefix": "built_in.reversed=>", 1018 | "body": [ 1019 | "alph = ['a', 'b', 'c', 'd']", 1020 | "ralph = reversed(alph)", 1021 | "for x in ralph:", 1022 | " print(x)" 1023 | ], 1024 | "description": "An example for using reversed" 1025 | }, 1026 | "round": { 1027 | "prefix": "round", 1028 | "body": "round(number[, ndigits])", 1029 | "description": "Rounds a numbers" 1030 | }, 1031 | "built_in.round=>_1": { 1032 | "prefix": "built_in.round=>_1", 1033 | "body": [ 1034 | "x = round(5.76543, 2)", 1035 | "print(x)" 1036 | ], 1037 | "description": "An example for using round" 1038 | }, 1039 | "built_in.round=>_2": { 1040 | "prefix": "built_in.round=>_2", 1041 | "body": [ 1042 | "x = round(5.76543)", 1043 | "print(x)" 1044 | ], 1045 | "description": "An example for using round" 1046 | }, 1047 | "set": { 1048 | "prefix": "set", 1049 | "body": "set(iterable)", 1050 | "description": "Returns a new set object" 1051 | }, 1052 | "built_in.set=>": { 1053 | "prefix": "built_in.set=>", 1054 | "body": [ 1055 | "x = set(('apple', 'banana', 'cherry'))", 1056 | "print(x)" 1057 | ], 1058 | "description": "An example for using set" 1059 | }, 1060 | "setattr": { 1061 | "prefix": "setattr", 1062 | "body": "setattr(object, name, value)", 1063 | "description": "Sets an attribute (property/method) of an object" 1064 | }, 1065 | "built_in.setattr=>": { 1066 | "prefix": "built_in.setattr=>", 1067 | "body": [ 1068 | "class Person:", 1069 | " name = 'John'", 1070 | " age = 36", 1071 | " country = 'Norway'", 1072 | "setattr(Person, 'age', 40)", 1073 | "# The age property will now have the value: 40", 1074 | "x = getattr(Person, 'age')", 1075 | "print(x)" 1076 | ], 1077 | "description": "An example for using setattr" 1078 | }, 1079 | "slice": { 1080 | "prefix": "slice", 1081 | "body": "slice(start, end, step)", 1082 | "description": "Returns a slice object" 1083 | }, 1084 | "built_in.slice=>_1": { 1085 | "prefix": "built_in.slice=>_1", 1086 | "body": [ 1087 | "a = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')", 1088 | "x = slice(2)", 1089 | "print(a[x])" 1090 | ], 1091 | "description": "An example for using slice" 1092 | }, 1093 | "built_in.slice=>_2": { 1094 | "prefix": "built_in.slice=>_2", 1095 | "body": [ 1096 | "a = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')", 1097 | "x = slice(3, 5)", 1098 | "print(a[x])" 1099 | ], 1100 | "description": "An example for using slice" 1101 | }, 1102 | "built_in.slice=>_3": { 1103 | "prefix": "built_in.slice=>_3", 1104 | "body": [ 1105 | "a = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')", 1106 | "x = slice(0, 8, 3)", 1107 | "print(a[x])" 1108 | ], 1109 | "description": "An example for using slice" 1110 | }, 1111 | "sorted": { 1112 | "prefix": "sorted", 1113 | "body": "sorted(iterable, key=key, reverse=reverse)", 1114 | "description": "Returns a sorted list" 1115 | }, 1116 | "built_in.sorted=>_1": { 1117 | "prefix": "built_in.sorted=>_1", 1118 | "body": [ 1119 | "a = ('b', 'g', 'a', 'd', 'f', 'c', 'h', 'e')", 1120 | "x = sorted(a)", 1121 | "print(x)" 1122 | ], 1123 | "description": "An example for using sorted" 1124 | }, 1125 | "built_in.sorted=>_2": { 1126 | "prefix": "built_in.sorted=>_2", 1127 | "body": [ 1128 | "a = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')", 1129 | "x = sorted(a, reverse=True)", 1130 | "print(x)" 1131 | ], 1132 | "description": "An example for using sorted" 1133 | }, 1134 | "built_in.sorted=>_3": { 1135 | "prefix": "built_in.sorted=>_3", 1136 | "body": [ 1137 | "a = ('b', 'g', 'a', 'd', 'f', 'c', 'h', 'e')", 1138 | "x = sorted(a)", 1139 | "print(x)" 1140 | ], 1141 | "description": "An example for using sorted" 1142 | }, 1143 | "staticmethod": { 1144 | "prefix": "staticmethod", 1145 | "body": "staticmethod(function)", 1146 | "description": "Converts a method into a static method" 1147 | }, 1148 | "str": { 1149 | "prefix": "str", 1150 | "body": "str(object, encoding=encoding, errors=errors)", 1151 | "description": "Returns a string object" 1152 | }, 1153 | "built_in.str=>": { 1154 | "prefix": "built_in.str=>", 1155 | "body": [ 1156 | "x = str(3.5)", 1157 | "print(x)" 1158 | ], 1159 | "description": "An example for using str" 1160 | }, 1161 | "sum": { 1162 | "prefix": "sum", 1163 | "body": "sum(iterable, start)", 1164 | "description": "Sums the items of an iterator" 1165 | }, 1166 | "built_in.sum=>_1": { 1167 | "prefix": "built_in.sum=>_1", 1168 | "body": [ 1169 | "a = (1, 2, 3, 4, 5)", 1170 | "x = sum(a)", 1171 | "print(x)" 1172 | ], 1173 | "description": "An example for using sum" 1174 | }, 1175 | "built_in.sum=>_2": { 1176 | "prefix": "built_in.sum=>_2", 1177 | "body": [ 1178 | "a = (1, 2, 3, 4, 5)", 1179 | "x = sum(a, 7)", 1180 | "print(x)" 1181 | ], 1182 | "description": "An example for using sum" 1183 | }, 1184 | "super": { 1185 | "prefix": "super", 1186 | "body": "super(type[, object-or-type])", 1187 | "description": "Return a proxy object that delegates method calls to a parent or sibling class of type." 1188 | }, 1189 | "tuple": { 1190 | "prefix": "tuple", 1191 | "body": "tuple(iterable)", 1192 | "description": "Returns a tuple" 1193 | }, 1194 | "built_in.tuple=>": { 1195 | "prefix": "built_in.tuple=>", 1196 | "body": [ 1197 | "x = tuple(('apple', 'banana', 'cherry'))", 1198 | "print(x)" 1199 | ], 1200 | "description": "An example for using tuple" 1201 | }, 1202 | "type": { 1203 | "prefix": "type", 1204 | "body": "type(object, bases, dict)", 1205 | "description": "Returns the type of an object" 1206 | }, 1207 | "built_in.type=>": { 1208 | "prefix": "built_in.type=>", 1209 | "body": [ 1210 | "a = ('apple', 'banana', 'cherry')", 1211 | "b = 'Hello World'", 1212 | "c = 33", 1213 | "x = type(a)", 1214 | "y = type(b)", 1215 | "z = type(c)" 1216 | ], 1217 | "description": "An example for using type" 1218 | }, 1219 | "unichr": { 1220 | "prefix": "unichr", 1221 | "body": "unichr(i)", 1222 | "description": "Return the Unicode string of one character whose Unicode code is the integer i." 1223 | }, 1224 | "vars": { 1225 | "prefix": "vars", 1226 | "body": "vars(object)", 1227 | "description": "Returns the __dict__ property of an object" 1228 | }, 1229 | "built_in.vars=>": { 1230 | "prefix": "built_in.vars=>", 1231 | "body": [ 1232 | "class Person:", 1233 | " name = 'John'", 1234 | " age = 36", 1235 | " country = 'norway'", 1236 | "x = vars(Person)" 1237 | ], 1238 | "description": "An example for using vars" 1239 | }, 1240 | "zip": { 1241 | "prefix": "zip", 1242 | "body": "zip(iterator1, iterqator2, iterator3 ...)", 1243 | "description": "Returns an iterator, from two or more iterators" 1244 | }, 1245 | "built_in.zip=>_1": { 1246 | "prefix": "built_in.zip=>_1", 1247 | "body": [ 1248 | "a = ('John', 'Charles', 'Mike')", 1249 | "b = ('Jenny', 'Christy', 'Monica')", 1250 | "x = zip(a, b)", 1251 | "#use the tuple() function to display a readable version of the result:", 1252 | "print(tuple(x))" 1253 | ], 1254 | "description": "An example for using zip" 1255 | }, 1256 | "built_in.zip=>_2": { 1257 | "prefix": "built_in.zip=>_2", 1258 | "body": [ 1259 | "a = ('John', 'Charles', 'Mike')", 1260 | "b = ('Jenny', 'Christy', 'Monica', 'Vicky')", 1261 | "x = zip(a, b)", 1262 | "#use the tuple() function to display a readable version of the result:", 1263 | "print(tuple(x))" 1264 | ], 1265 | "description": "An example for using zip" 1266 | }, 1267 | "if": { 1268 | "prefix": "if", 1269 | "body": [ 1270 | "if condition:", 1271 | " pass" 1272 | ], 1273 | "description": "if Statements" 1274 | }, 1275 | "ifelif": { 1276 | "prefix": "ifelif", 1277 | "body": [ 1278 | "if condition:", 1279 | " pass", 1280 | "elif condition:", 1281 | " pass" 1282 | ], 1283 | "description": "if/else if Statements" 1284 | }, 1285 | "ifelifelse": { 1286 | "prefix": "ifelifelse", 1287 | "body": [ 1288 | "if condition:", 1289 | " pass", 1290 | "elif condition:", 1291 | " pass", 1292 | "else:", 1293 | " pass" 1294 | ], 1295 | "description": "if/else if/else Statements" 1296 | }, 1297 | "ifel": { 1298 | "prefix": "ifelse", 1299 | "body": [ 1300 | "if condition:", 1301 | " pass", 1302 | "else:", 1303 | " pass" 1304 | ], 1305 | "description": "if/else Statements" 1306 | }, 1307 | "elif": { 1308 | "prefix": "else", 1309 | "body": [ 1310 | "else:", 1311 | " pass" 1312 | ], 1313 | "description": "else Statements" 1314 | }, 1315 | "ifshort": { 1316 | "prefix": "ifshort", 1317 | "body": "print('A') if a > b else print('A')", 1318 | "description": "ifshort Statements" 1319 | }, 1320 | "lambda": { 1321 | "prefix": "lambda", 1322 | "body": "lambda arguments : expression", 1323 | "description": "A lambda function can take any number of arguments, but can only have one expression." 1324 | }, 1325 | "for": { 1326 | "prefix": "for", 1327 | "body": [ 1328 | "for item in range:", 1329 | " " 1330 | ], 1331 | "description": "for Statements" 1332 | }, 1333 | "for=>": { 1334 | "prefix": "for=>", 1335 | "body": [ 1336 | "fruits = ['apple', 'banana', 'cherry']", 1337 | "for x in fruits:", 1338 | " print(x)" 1339 | ], 1340 | "description": "An example for using for" 1341 | }, 1342 | "for=>through_a_string": { 1343 | "prefix": "for=>through_a_string", 1344 | "body": [ 1345 | "for x in 'banana':", 1346 | " print(x)" 1347 | ], 1348 | "description": "An example for using for" 1349 | }, 1350 | "for=>break_statement": { 1351 | "prefix": "for=>break_statement", 1352 | "body": [ 1353 | "fruits = ['apple', 'banana', 'cherry']", 1354 | "for x in fruits:", 1355 | " print(x)", 1356 | " if x == 'banana':", 1357 | " break" 1358 | ], 1359 | "description": "An example for using for" 1360 | }, 1361 | "for=>continue_statement": { 1362 | "prefix": "for=>continue_statement", 1363 | "body": [ 1364 | "fruits = ['apple', 'banana', 'cherry']", 1365 | "for x in fruits:", 1366 | " print(x)", 1367 | " if x == 'banana':", 1368 | " continue", 1369 | " print(x)" 1370 | ], 1371 | "description": "An example for using for" 1372 | }, 1373 | "for=>range_function_1": { 1374 | "prefix": "for=>range_function_1", 1375 | "body": [ 1376 | "for x in range(6):", 1377 | " print(x)" 1378 | ], 1379 | "description": "An example for using for" 1380 | }, 1381 | "for=>range_function_2": { 1382 | "prefix": "for=>range_function_2", 1383 | "body": [ 1384 | "for x in range(2, 6):", 1385 | " print(x)" 1386 | ], 1387 | "description": "An example for using for" 1388 | }, 1389 | "for=>range_function_3": { 1390 | "prefix": "for=>range_function_3", 1391 | "body": [ 1392 | "for x in range(2, 30, 3):", 1393 | " print(x)" 1394 | ], 1395 | "description": "An example for using for" 1396 | }, 1397 | "for=>for_else": { 1398 | "prefix": "for=>for_else", 1399 | "body": [ 1400 | "for x in range(2, 6):", 1401 | " print(x)", 1402 | "else:", 1403 | " print('Finally finished!')" 1404 | ], 1405 | "description": "An example for using for" 1406 | }, 1407 | "for=>nested_loops": { 1408 | "prefix": "for=>for_else", 1409 | "body": [ 1410 | "adj = ['red', 'big', 'tasty']", 1411 | "fruits = ['apple', 'banana', 'cherry']", 1412 | "for x in adj:", 1413 | " for y in fruits:", 1414 | " print(x, y)" 1415 | ], 1416 | "description": "An example for using for" 1417 | }, 1418 | "while": { 1419 | "prefix": "while", 1420 | "body": [ 1421 | "while expression:", 1422 | " pass" 1423 | ], 1424 | "description": "while Statements" 1425 | }, 1426 | "while_else": { 1427 | "prefix": "while_else", 1428 | "body": [ 1429 | "while expression:", 1430 | " pass", 1431 | "else:", 1432 | " pass" 1433 | ], 1434 | "description": "while Statements" 1435 | }, 1436 | "while=>": { 1437 | "prefix": "while=>", 1438 | "body": [ 1439 | "i = 1", 1440 | "while i < 6:", 1441 | " print(i)", 1442 | " i += 1" 1443 | ], 1444 | "description": "while Statements" 1445 | }, 1446 | "while=>break_statement": { 1447 | "prefix": "while=>break_statement", 1448 | "body": [ 1449 | "i = 1", 1450 | "while i < 6:", 1451 | " print(i)", 1452 | " if i == 3:", 1453 | " break", 1454 | " i += 1" 1455 | ], 1456 | "description": "while Statements" 1457 | }, 1458 | "while=>continue_statement": { 1459 | "prefix": "while=>continue_statement", 1460 | "body": [ 1461 | "i = 1", 1462 | "while i < 6:", 1463 | " i += 1", 1464 | " print(i)", 1465 | " if i == 3:", 1466 | " continue", 1467 | " print(i)" 1468 | ], 1469 | "description": "while Statements" 1470 | }, 1471 | "function": { 1472 | "prefix": "function=>", 1473 | "body": [ 1474 | "def name(args):", 1475 | " pass" 1476 | ], 1477 | "description": "Defining Function" 1478 | }, 1479 | "def": { 1480 | "prefix": "def=>", 1481 | "body": [ 1482 | "def name(args):", 1483 | " pass" 1484 | ], 1485 | "description": "Defining Function" 1486 | }, 1487 | "def=>with_default_value": { 1488 | "prefix": "def=>with_default_value", 1489 | "body": [ 1490 | "def name(name, lastName='john')", 1491 | " pass" 1492 | ], 1493 | "description": "Defining Function wqith default values" 1494 | }, 1495 | "capitalize": { 1496 | "prefix": ".capitalize", 1497 | "body": ".capitalize()", 1498 | "description": "Converts the first character to upper case" 1499 | }, 1500 | "string.capitalize=>_1": { 1501 | "prefix": "string.capitalize=>_1", 1502 | "body": [ 1503 | "txt = hello, and welcome to my world.", 1504 | "", 1505 | "x = txt.capitalize()", 1506 | "", 1507 | "print (x)" 1508 | ], 1509 | "description": "An example for using capitalize" 1510 | }, 1511 | "string.capitalize=>_2": { 1512 | "prefix": "string.capitalize=>_2", 1513 | "body": [ 1514 | "txt = '36 is my age.'", 1515 | "", 1516 | "x = txt.capitalize()", 1517 | "", 1518 | "print (x)" 1519 | ], 1520 | "description": "An example for using capitalize" 1521 | }, 1522 | "casefold": { 1523 | "prefix": ".casefold", 1524 | "body": ".casefold()", 1525 | "description": "Converts string into lower case" 1526 | }, 1527 | "string.casefold=>": { 1528 | "prefix": "string.casefold=>", 1529 | "body": [ 1530 | "txt = 'Hello, And Welcome To My World!'", 1531 | "", 1532 | "x = txt.casefold()", 1533 | "", 1534 | "print(x)" 1535 | ], 1536 | "description": "An example for using casefold" 1537 | }, 1538 | "center": { 1539 | "prefix": ".center", 1540 | "body": ".center()", 1541 | "description": "Returns a centered string" 1542 | }, 1543 | "string.center=>_1": { 1544 | "prefix": "string.center=>_1", 1545 | "body": [ 1546 | "txt = 'banana'", 1547 | "", 1548 | "x = txt.center(20)", 1549 | "", 1550 | "print(x)" 1551 | ], 1552 | "description": "An example for using center" 1553 | }, 1554 | "string.center=>_2": { 1555 | "prefix": "string.center=>_2", 1556 | "body": [ 1557 | "txt = 'banana'", 1558 | "", 1559 | "x = txt.center(20,'O')", 1560 | "", 1561 | "print(x)" 1562 | ], 1563 | "description": "An example for using center" 1564 | }, 1565 | "string.count": { 1566 | "prefix": ".count", 1567 | "body": ".count()", 1568 | "description": "Returns the number of times a specified value occurs in a string" 1569 | }, 1570 | "string.count=>_1": { 1571 | "prefix": "string.count=>_1", 1572 | "body": [ 1573 | "txt = 'I love apples, apple are my favorite fruit'", 1574 | "", 1575 | "x = txt.count('apple')", 1576 | "", 1577 | "print(x)" 1578 | ], 1579 | "description": "An example for using count" 1580 | }, 1581 | "string.count=>_2": { 1582 | "prefix": "string.count=>_2", 1583 | "body": [ 1584 | "txt = 'I love apples, apple are my favorite fruit'", 1585 | "", 1586 | "x = txt.count('apple', 10, 24)", 1587 | "", 1588 | "print(x)" 1589 | ], 1590 | "description": "An example for using count" 1591 | }, 1592 | "encode": { 1593 | "prefix": ".encode", 1594 | "body": ".encode()", 1595 | "description": "Returns an encoded version of the string" 1596 | }, 1597 | "string.encode=>": { 1598 | "prefix": "string.encode=>", 1599 | "body": [ 1600 | "txt = 'My name is Ståle'", 1601 | "", 1602 | "x = txt.encode()", 1603 | "", 1604 | "print()" 1605 | ], 1606 | "description": "An example for using encode" 1607 | }, 1608 | "string.encode=>": { 1609 | "prefix": "string.encode=>", 1610 | "body": [ 1611 | "txt = 'My name is Ståle'", 1612 | "", 1613 | "print(txt.encode(encoding='ascii',errors='backslashreplace')", 1614 | "print(txt.encode(encoding='ascii',errors='ignore')", 1615 | "print(txt.encode(encoding='ascii',errors='namereplace')", 1616 | "print(txt.encode(encoding='ascii',errors='replace')", 1617 | "print(txt.encode(encoding='ascii',errors='xmlcharrefreplace')", 1618 | "print(txt.encode(encoding='ascii',errors='strict')" 1619 | ], 1620 | "description": "An example for using encode" 1621 | }, 1622 | "endswith": { 1623 | "prefix": ".endswith", 1624 | "body": ".endswith()", 1625 | "description": "Returns true if the string ends with the specified value" 1626 | }, 1627 | "string.endswith=>_1": { 1628 | "prefix": "string.endswith=>_1", 1629 | "body": [ 1630 | "txt = 'Hello, And Welcome To My World!'", 1631 | "", 1632 | "x = txt.endswith('.')", 1633 | "", 1634 | "print(x)" 1635 | ], 1636 | "description": "An example for using endswith" 1637 | }, 1638 | "string.endswith=>_2": { 1639 | "prefix": "string.endswith=>_2", 1640 | "body": [ 1641 | "txt = 'Hello, And Welcome To My World!'", 1642 | "", 1643 | "x = txt.endswith('my world.', 5, 11)", 1644 | "", 1645 | "print(x)" 1646 | ], 1647 | "description": "An example for using endswith" 1648 | }, 1649 | "expandtabs": { 1650 | "prefix": ".expandtabs", 1651 | "body": ".expandtabs()", 1652 | "description": "Sets the tab size of the string" 1653 | }, 1654 | "string.expandtabs=>_1": { 1655 | "prefix": "string.expandtabs=>_1", 1656 | "body": [ 1657 | "txt = 'H\te\tl\tl\to'", 1658 | "", 1659 | "x = txt.expandtabs(2)", 1660 | "", 1661 | "print(x)" 1662 | ], 1663 | "description": "An example for using expandtabs" 1664 | }, 1665 | "string.expandtabs=>_2": { 1666 | "prefix": "string.expandtabs=>_2", 1667 | "body": [ 1668 | "txt = 'H\te\tl\tl\to'", 1669 | "", 1670 | "print(txt)", 1671 | "print(txt.expandtabs())", 1672 | "print(txt.expandtabs(2))", 1673 | "print(txt.expandtabs(4))", 1674 | "print(txt.expandtabs(10))" 1675 | ], 1676 | "description": "An example for using expandtabs" 1677 | }, 1678 | "find": { 1679 | "prefix": ".find", 1680 | "body": ".find()", 1681 | "description": "Searches the string for a specified value and returns the position of where it was found" 1682 | }, 1683 | "string.find=>_1": { 1684 | "prefix": "string.find=>_1", 1685 | "body": [ 1686 | "txt = 'Hello, welcome to my world.'", 1687 | "", 1688 | "x = txt.find('welcome')", 1689 | "", 1690 | "print(x)" 1691 | ], 1692 | "description": "An example for using find" 1693 | }, 1694 | "string.find=>_2": { 1695 | "prefix": "string.find=>_2", 1696 | "body": [ 1697 | "txt = 'Hello, And Welcome To My World!'", 1698 | "", 1699 | "x = txt.find('e')", 1700 | "", 1701 | "print(x)" 1702 | ], 1703 | "description": "An example for using find" 1704 | }, 1705 | "string.find=>_3": { 1706 | "prefix": "string.find=>_3", 1707 | "body": [ 1708 | "txt = 'Hello, And Welcome To My World!'", 1709 | "", 1710 | "x = txt.find('e', 5, 10)", 1711 | "", 1712 | "print(x)" 1713 | ], 1714 | "description": "An example for using find" 1715 | }, 1716 | "string.find=>_4": { 1717 | "prefix": "string.find=>_4", 1718 | "body": [ 1719 | "txt = 'Hello, And Welcome To My World!'", 1720 | "", 1721 | "print(txt.find('q'))", 1722 | "print(txt.index('q'))" 1723 | ], 1724 | "description": "An example for using find" 1725 | }, 1726 | "format": { 1727 | "prefix": ".format", 1728 | "body": ".format()", 1729 | "description": "Formats specified values in a string" 1730 | }, 1731 | "string.format=>": { 1732 | "prefix": "string.format=>", 1733 | "body": [ 1734 | "# default arguments", 1735 | "print('Hello {}, your balance is {}.'.format('Adam', 230.2346))", 1736 | "", 1737 | "# positional arguments", 1738 | "print('Hello {0}, your balance is {1}.'.format('Adam', 230.2346))", 1739 | "", 1740 | "# keyword arguments", 1741 | "print('Hello {name}, your balance is {blc}.'.format(name='Adam', blc=230.2346))", 1742 | "", 1743 | "# mixed arguments", 1744 | "print('Hello {0}, your balance is {blc}.'.format('Adam', blc=230.2346))" 1745 | ], 1746 | "description": "An example for using format" 1747 | }, 1748 | "format_map": { 1749 | "prefix": ".format_map", 1750 | "body": ".format_map()", 1751 | "description": "Formats specified values in a string" 1752 | }, 1753 | "string.format_map=>": { 1754 | "prefix": "string.format_map=>", 1755 | "body": [ 1756 | "point = {'x':4,'y':-5}", 1757 | "print('{x} {y}'.format_map(point))", 1758 | "", 1759 | "point = {'x':4,'y':-5, 'z': 0}", 1760 | "print('{x} {y} {z}'.format_map(point))" 1761 | ], 1762 | "description": "An example for using format_map" 1763 | }, 1764 | "index": { 1765 | "prefix": ".index", 1766 | "body": ".index()", 1767 | "description": "Searches the string for a specified value and returns the position of where it was found" 1768 | }, 1769 | "string.index=>_1": { 1770 | "prefix": "string.index=>_1", 1771 | "body": [ 1772 | "txt = 'Hello, welcome to my world.'", 1773 | "", 1774 | "x = txt.index('welcome')", 1775 | "", 1776 | "print(x)" 1777 | ], 1778 | "description": "An example for using index" 1779 | }, 1780 | "string.index=>_2": { 1781 | "prefix": "string.index=>_2", 1782 | "body": [ 1783 | "txt = 'Hello, And Welcome To My World!'", 1784 | "", 1785 | "x = txt.index('e')", 1786 | "", 1787 | "print(x)" 1788 | ], 1789 | "description": "An example for using index" 1790 | }, 1791 | "string.index=>_3": { 1792 | "prefix": "string.index=>_3", 1793 | "body": [ 1794 | "txt = 'Hello, And Welcome To My World!'", 1795 | "", 1796 | "x = txt.index('e', 5, 10)", 1797 | "", 1798 | "print(x)" 1799 | ], 1800 | "description": "An example for using index" 1801 | }, 1802 | "string.index=>_4": { 1803 | "prefix": "string.index=>_4", 1804 | "body": [ 1805 | "txt = 'Hello, And Welcome To My World!'", 1806 | "", 1807 | "print(txt.find('q'))", 1808 | "print(txt.index('q'))" 1809 | ], 1810 | "description": "An example for using index" 1811 | }, 1812 | "isalnum": { 1813 | "prefix": ".isalnum", 1814 | "body": ".isalnum()", 1815 | "description": "Returns True if all characters in the string are alphanumeric" 1816 | }, 1817 | "string.isalnum=>": { 1818 | "prefix": "string.isalnum=>", 1819 | "body": [ 1820 | "txt = 'Company12'", 1821 | "x = txt.isalnum()", 1822 | "print(x)" 1823 | ], 1824 | "description": "An example for using isalnum" 1825 | }, 1826 | "string.isalnum=>": { 1827 | "prefix": "string.isalnum=>", 1828 | "body": [ 1829 | "txt = 'Company 12'", 1830 | "x = txt.isalnum()", 1831 | "print(x)" 1832 | ], 1833 | "description": "An example for using isalnum" 1834 | }, 1835 | "isalpha": { 1836 | "prefix": ".isalpha", 1837 | "body": ".isalpha()", 1838 | "description": "Returns True if all characters in the string are in the alphabet" 1839 | }, 1840 | "string.isalpha=>": { 1841 | "prefix": "string.isalpha=>", 1842 | "body": [ 1843 | "txt = 'Company10'", 1844 | "x = txt.isalpha()", 1845 | "print(x)" 1846 | ], 1847 | "description": "An example for using isalpha" 1848 | }, 1849 | "isdecimal": { 1850 | "prefix": ".isdecimal", 1851 | "body": ".isdecimal()", 1852 | "description": "Returns True if all characters in the string are decimals" 1853 | }, 1854 | "string.isdecimal=>": { 1855 | "prefix": "string.isdecimal=>", 1856 | "body": [ 1857 | "txt = '\u0033' #unicode for 3", 1858 | "x = txt.isdecimal()", 1859 | "print(x)" 1860 | ], 1861 | "description": "An example for using isdecimal" 1862 | }, 1863 | "string.isdecimal=>": { 1864 | "prefix": "string.isdecimal=>", 1865 | "body": [ 1866 | "a = '\u0030' #unicode for 0", 1867 | "b = '\u0047' #unicode for G", 1868 | "print(a.isdecimal())", 1869 | "print(b.isdecimal())" 1870 | ], 1871 | "description": "An example for using isdecimal" 1872 | }, 1873 | "isdigit": { 1874 | "prefix": ".isdigit", 1875 | "body": ".isdigit()", 1876 | "description": "Returns True if all characters in the string are digits" 1877 | }, 1878 | "string.isdigit=>": { 1879 | "prefix": "string.isdigit=>", 1880 | "body": [ 1881 | "txt = '50800'", 1882 | "x = txt.isdigit()", 1883 | "print(x)" 1884 | ], 1885 | "description": "An example for using isdigit" 1886 | }, 1887 | "string.isdigit=>": { 1888 | "prefix": "string.isdigit=>", 1889 | "body": [ 1890 | "a = '\u0030' #unicode for 0", 1891 | "b = '\u00B2' #unicode for ²", 1892 | "print(a.isdigit())", 1893 | "print(b.isdigit())" 1894 | ], 1895 | "description": "An example for using isdigit" 1896 | }, 1897 | "isidentifier": { 1898 | "prefix": ".isidentifier", 1899 | "body": ".isidentifier()", 1900 | "description": "Returns True if the string is an identifier" 1901 | }, 1902 | "string.isidentifier=>": { 1903 | "prefix": "string.isidentifier=>", 1904 | "body": [ 1905 | "txt = 'Demo'", 1906 | "x = txt.isidentifier()", 1907 | "print(x)" 1908 | ], 1909 | "description": "An example for using isidentifier" 1910 | }, 1911 | "string.isidentifier=>": { 1912 | "prefix": "string.isidentifier=>", 1913 | "body": [ 1914 | "a = 'MyFolder'", 1915 | "b = 'Demo002'", 1916 | "c = '2bring'", 1917 | "d = 'my demo'", 1918 | "print(a.isidentifier())", 1919 | "print(b.isidentifier())", 1920 | "print(c.isidentifier())", 1921 | "print(d.isidentifier())" 1922 | ], 1923 | "description": "An example for using isidentifier" 1924 | }, 1925 | "islower": { 1926 | "prefix": ".islower", 1927 | "body": ".islower()", 1928 | "description": "Returns True if all characters in the string are lower case" 1929 | }, 1930 | "string.islower=>": { 1931 | "prefix": "string.islower=>", 1932 | "body": [ 1933 | "txt = 'hello world!'", 1934 | "x = txt.islower()", 1935 | "print(x)" 1936 | ], 1937 | "description": "An example for using islower" 1938 | }, 1939 | "string.islower=>": { 1940 | "prefix": "string.islower=>", 1941 | "body": [ 1942 | "a = 'Hello world!'", 1943 | "b = 'hello 123'", 1944 | "c = 'mynameisPeter'", 1945 | "print(a.islower())", 1946 | "print(b.islower())", 1947 | "print(c.islower())" 1948 | ], 1949 | "description": "An example for using islower" 1950 | }, 1951 | "isnumeric": { 1952 | "prefix": ".isnumeric", 1953 | "body": ".isnumeric()", 1954 | "description": "Returns True if all characters in the string are numeric" 1955 | }, 1956 | "string.isnumeric=>": { 1957 | "prefix": "string.isnumeric=>", 1958 | "body": [ 1959 | "txt = '565543'", 1960 | "x = txt.isnumeric()", 1961 | "print(x)" 1962 | ], 1963 | "description": "An example for using isnumeric" 1964 | }, 1965 | "string.isnumeric=>": { 1966 | "prefix": "string.isnumeric=>", 1967 | "body": [ 1968 | "a = '\u0030' #unicode for 0", 1969 | "b = '\u00B2' #unicode for ²", 1970 | "c = '10km2'", 1971 | "print(a.isnumeric())", 1972 | "print(b.isnumeric())", 1973 | "print(c.isnumeric())" 1974 | ], 1975 | "description": "An example for using isnumeric" 1976 | }, 1977 | "isprintable": { 1978 | "prefix": ".isprintable", 1979 | "body": ".isprintable()", 1980 | "description": "Returns True if all characters in the string are printable" 1981 | }, 1982 | "string.isprintable=>": { 1983 | "prefix": "string.isprintable=>", 1984 | "body": [ 1985 | "txt = 'Hello! Are you #1?'", 1986 | "x = txt.isprintable()", 1987 | "print(x)" 1988 | ], 1989 | "description": "An example for using isprintable" 1990 | }, 1991 | "string.isprintable=>": { 1992 | "prefix": "string.isprintable=>", 1993 | "body": [ 1994 | "txt = 'Hello!\nAre you #1?'", 1995 | "x = txt.isprintable()", 1996 | "print(x)" 1997 | ], 1998 | "description": "An example for using isprintable" 1999 | }, 2000 | "isspace": { 2001 | "prefix": ".isspace", 2002 | "body": ".isspace()", 2003 | "description": "Returns True if all characters in the string are whitespaces" 2004 | }, 2005 | "string.isspace=>": { 2006 | "prefix": "string.isspace=>", 2007 | "body": [ 2008 | "txt = ' '", 2009 | "x = txt.isspace()", 2010 | "print(x)" 2011 | ], 2012 | "description": "An example for using isspace" 2013 | }, 2014 | "string.isspace=>": { 2015 | "prefix": "string.isspace=>", 2016 | "body": [ 2017 | "txt = ' s '", 2018 | "x = txt.isspace()", 2019 | "print(x)" 2020 | ], 2021 | "description": "An example for using isspace" 2022 | }, 2023 | "istitle": { 2024 | "prefix": ".istitle", 2025 | "body": ".istitle()", 2026 | "description": "Returns True if the string follows the rules of a title" 2027 | }, 2028 | "string.istitle=>": { 2029 | "prefix": "string.istitle=>", 2030 | "body": [ 2031 | "txt = 'Hello, And Welcome To My World!'", 2032 | "x = txt.istitle()", 2033 | "print(x)" 2034 | ], 2035 | "description": "An example for using istitle" 2036 | }, 2037 | "string.istitle=>": { 2038 | "prefix": "string.istitle=>", 2039 | "body": [ 2040 | "a = 'HELLO, AND WELCOME TO MY WORLD'", 2041 | "b = 'Hello'", 2042 | "c = '22 Names'", 2043 | "d = 'This Is %'!?'", 2044 | "print(a.istitle())", 2045 | "print(b.istitle())", 2046 | "print(c.istitle())", 2047 | "print(d.istitle())" 2048 | ], 2049 | "description": "An example for using istitle" 2050 | }, 2051 | "isupper": { 2052 | "prefix": ".isupper", 2053 | "body": ".isupper()", 2054 | "description": "Returns True if all characters in the string are upper case" 2055 | }, 2056 | "string.isupper=>": { 2057 | "prefix": "string.isupper=>", 2058 | "body": [ 2059 | "txt = 'THIS IS NOW!'", 2060 | "x = txt.isupper()", 2061 | "print(x)" 2062 | ], 2063 | "description": "An example for using isupper" 2064 | }, 2065 | "string.isupper=>": { 2066 | "prefix": "string.isupper=>", 2067 | "body": [ 2068 | "a = 'Hello World!'", 2069 | "b = 'hello 123'", 2070 | "c = 'MY NAME IS PETER'", 2071 | "print(a.isupper())", 2072 | "print(b.isupper())", 2073 | "print(c.isupper())" 2074 | ], 2075 | "description": "An example for using isupper" 2076 | }, 2077 | "join": { 2078 | "prefix": ".join", 2079 | "body": ".join()", 2080 | "description": "Joins the elements of an iterable to the end of the string" 2081 | }, 2082 | "string.join=>": { 2083 | "prefix": "string.join=>", 2084 | "body": [ 2085 | "myTuple = ('John', 'Peter', 'Vicky')", 2086 | "x = '#'.join(myTuple)", 2087 | "print(x)" 2088 | ], 2089 | "description": "An example for using join" 2090 | }, 2091 | "string.join=>": { 2092 | "prefix": "string.join=>", 2093 | "body": [ 2094 | "myDict = {'name': 'John', 'country': 'Norway'}", 2095 | "mySeparator = 'TEST'", 2096 | "x = mySeparator.join(myDict)", 2097 | "print(x)" 2098 | ], 2099 | "description": "An example for using join" 2100 | }, 2101 | "ljust": { 2102 | "prefix": ".ljust", 2103 | "body": ".ljust()", 2104 | "description": "Returns a left justified version of the string" 2105 | }, 2106 | "string.ljust=>": { 2107 | "prefix": "string.ljust=>", 2108 | "body": [ 2109 | "txt = 'banana'", 2110 | "x = txt.ljust(20)", 2111 | "print(x, 'is my favorite fruit.')" 2112 | ], 2113 | "description": "An example for using ljust" 2114 | }, 2115 | "string.ljust=>": { 2116 | "prefix": "string.ljust=>", 2117 | "body": [ 2118 | "txt = 'banana'", 2119 | "x = txt.ljust(20, 'O')", 2120 | "print(x)" 2121 | ], 2122 | "description": "An example for using ljust" 2123 | }, 2124 | "lower": { 2125 | "prefix": ".lower", 2126 | "body": ".lower()", 2127 | "description": "Converts a string into lower case" 2128 | }, 2129 | "string.lower=>": { 2130 | "prefix": "string.lower=>", 2131 | "body": [ 2132 | "txt = 'Hello my FRIENDS'", 2133 | "x = txt.lower()", 2134 | "print(x)" 2135 | ], 2136 | "description": "An example for using lower" 2137 | }, 2138 | "lstrip": { 2139 | "prefix": ".lstrip", 2140 | "body": ".lstrip()", 2141 | "description": "Returns a left trim version of the string" 2142 | }, 2143 | "string.lstrip=>": { 2144 | "prefix": "string.lstrip=>", 2145 | "body": [ 2146 | "txt = ' banana '", 2147 | "x = txt.lstrip()", 2148 | "print('of all fruits', x, 'is my favorite')" 2149 | ], 2150 | "description": "An example for using lstrip" 2151 | }, 2152 | "string.lstrip=>": { 2153 | "prefix": "string.lstrip=>", 2154 | "body": [ 2155 | "txt = ',,,,,ssaaww.....banana'", 2156 | "x = txt.lstrip(',.asw')", 2157 | "print(x)" 2158 | ], 2159 | "description": "An example for using lstrip" 2160 | }, 2161 | "maketrans": { 2162 | "prefix": ".maketrans", 2163 | "body": ".maketrans()", 2164 | "description": "Returns a translation table to be used in translations" 2165 | }, 2166 | "string.maketrans=>": { 2167 | "prefix": "string.maketrans=>", 2168 | "body": [ 2169 | "# example dictionary", 2170 | "dict = {'a': '123', 'b': '456', 'c': '789'}", 2171 | "string = 'abc'", 2172 | "print(string.maketrans(dict))" 2173 | ], 2174 | "description": "An example for using maketrans" 2175 | }, 2176 | "string.maketrans=>": { 2177 | "prefix": "string.maketrans=>", 2178 | "body": [ 2179 | "# example dictionary", 2180 | "dict = {97: '123', 98: '456', 99: '789'}", 2181 | "string = 'abc'", 2182 | "print(string.maketrans(dict))" 2183 | ], 2184 | "description": "An example for using maketrans" 2185 | }, 2186 | "partition": { 2187 | "prefix": ".partition", 2188 | "body": ".partition()", 2189 | "description": "Returns a tuple where the string is parted into three parts" 2190 | }, 2191 | "string.partition=>": { 2192 | "prefix": "string.partition=>", 2193 | "body": [ 2194 | "txt = 'I could eat bananas all day'", 2195 | "x = txt.partition('bananas')", 2196 | "print(x)" 2197 | ], 2198 | "description": "An example for using partition" 2199 | }, 2200 | "string.partition=>": { 2201 | "prefix": "string.partition=>", 2202 | "body": [ 2203 | "txt = 'I could eat bananas all day'", 2204 | "x = txt.partition('apples')", 2205 | "print(x)" 2206 | ], 2207 | "description": "An example for using partition" 2208 | }, 2209 | "replace": { 2210 | "prefix": ".replace", 2211 | "body": ".replace(x, y)", 2212 | "description": "Returns a string where a specified value is replaced with a specified value" 2213 | }, 2214 | "string.replace=>": { 2215 | "prefix": "string.replace=>", 2216 | "body": [ 2217 | "txt 'I like bananas'", 2218 | "x = txt.replace('bananas', 'apples')", 2219 | "print(x)" 2220 | ], 2221 | "description": "An example for using replace" 2222 | }, 2223 | "string.replace=>": { 2224 | "prefix": "string.replace=>", 2225 | "body": [ 2226 | "txt = 'one one was a race horse, two two was one too.'", 2227 | "x = txt.replace('one', 'three')", 2228 | "print(x)" 2229 | ], 2230 | "description": "An example for using replace" 2231 | }, 2232 | "string.replace=>": { 2233 | "prefix": "string.replace=>", 2234 | "body": [ 2235 | "txt = 'one one was a race horse, two two was one too.'", 2236 | "x = txt.replace('one', 'three', 2)", 2237 | "print(x)" 2238 | ], 2239 | "description": "An example for using replace" 2240 | }, 2241 | "rfind": { 2242 | "prefix": ".rfind", 2243 | "body": ".rfind()", 2244 | "description": "Searches the string for a specified value and returns the last position of where it was found" 2245 | }, 2246 | "string.rfind=>": { 2247 | "prefix": "string.rfind=>", 2248 | "body": [ 2249 | "txt = 'Mi casa, su casa.'", 2250 | "x = txt.rfind('casa')", 2251 | "print(x)" 2252 | ], 2253 | "description": "An example for using rfind" 2254 | }, 2255 | "string.rfind=>": { 2256 | "prefix": "string.rfind=>", 2257 | "body": [ 2258 | "txt = 'Hello, welcome to my world.'", 2259 | "x = txt.rfind('e')", 2260 | "print(x)" 2261 | ], 2262 | "description": "An example for using rfind" 2263 | }, 2264 | "string.rfind=>": { 2265 | "prefix": "string.rfind=>", 2266 | "body": [ 2267 | "txt = 'Hello, welcome to my world.'", 2268 | "x = txt.rfind('e', 5, 10)", 2269 | "print(x)" 2270 | ], 2271 | "description": "An example for using rfind" 2272 | }, 2273 | "string.rfind=>": { 2274 | "prefix": "string.rfind=>", 2275 | "body": [ 2276 | "txt = 'Hello, welcome to my world.'", 2277 | "print(txt.rfind('q'))", 2278 | "print(txt.rindex('q'))" 2279 | ], 2280 | "description": "An example for using rfind" 2281 | }, 2282 | "rindex": { 2283 | "prefix": ".rindex", 2284 | "body": ".rindex()", 2285 | "description": "Searches the string for a specified value and returns the last position of where it was found" 2286 | }, 2287 | "string.rindex=>": { 2288 | "prefix": "string.rindex=>", 2289 | "body": [ 2290 | "txt = 'Mi casa, su casa.'", 2291 | "x = txt.rindex('casa')", 2292 | "print(x)" 2293 | ], 2294 | "description": "An example for using rindex" 2295 | }, 2296 | "string.rindex=>": { 2297 | "prefix": "string.rindex=>", 2298 | "body": [ 2299 | "txt = 'Hello, welcome to my world.'", 2300 | "x = txt.rindex('e')", 2301 | "print(x)" 2302 | ], 2303 | "description": "An example for using rindex" 2304 | }, 2305 | "string.rindex=>": { 2306 | "prefix": "string.rindex=>", 2307 | "body": [ 2308 | "txt = 'Hello, welcome to my world.'", 2309 | "x = txt.rindex('e', 5, 10)", 2310 | "print(x)" 2311 | ], 2312 | "description": "An example for using rindex" 2313 | }, 2314 | "string.rindex=>": { 2315 | "prefix": "string.rindex=>", 2316 | "body": [ 2317 | "txt = 'Hello, welcome to my world.'", 2318 | "print(txt.rfind('q'))", 2319 | "print(txt.rindex('q'))" 2320 | ], 2321 | "description": "An example for using rindex" 2322 | }, 2323 | "rpartition": { 2324 | "prefix": ".rpartition", 2325 | "body": ".rpartition()", 2326 | "description": "Returns a tuple where the string is parted into three parts" 2327 | }, 2328 | "string.rpartition=>": { 2329 | "prefix": "string.rpartition=>", 2330 | "body": [ 2331 | "txt = 'I could eat bananas all day, bananas are my favorite fruit'", 2332 | "x = txt.rpartition('bananas')", 2333 | "print(x)" 2334 | ], 2335 | "description": "An example for using rpartition" 2336 | }, 2337 | "string.rpartition=>": { 2338 | "prefix": "string.rpartition=>", 2339 | "body": [ 2340 | "txt = 'I could eat bananas all day, bananas are my favorite fruit'", 2341 | "x = txt.rpartition('apples')", 2342 | "print(x)" 2343 | ], 2344 | "description": "An example for using rpartition" 2345 | }, 2346 | "rsplit": { 2347 | "prefix": ".rsplit", 2348 | "body": ".rsplit()", 2349 | "description": "Returns a right trim version of the string" 2350 | }, 2351 | "string.rsplit=>": { 2352 | "prefix": "string.rsplit=>", 2353 | "body": [ 2354 | "txt = 'apple, banana, cherry'", 2355 | "x = txt.rsplit(', ')", 2356 | "print(x)" 2357 | ], 2358 | "description": "An example for using rsplit" 2359 | }, 2360 | "string.rsplit=>": { 2361 | "prefix": "string.rsplit=>", 2362 | "body": [ 2363 | "txt = 'apple, banana, cherry'", 2364 | "# setting the max parameter to 1, will return a list with 2 elements!", 2365 | "x = txt.rsplit(', ', 1)", 2366 | "print(x)" 2367 | ], 2368 | "description": "An example for using rsplit" 2369 | }, 2370 | "string.rsplit=>": { 2371 | "prefix": "string.rsplit=>", 2372 | "body": [ 2373 | "txt = 'banana,,,,,ssaaww.....'", 2374 | "x = txt.rstrip(',.asw')", 2375 | "print(x)" 2376 | ], 2377 | "description": "An example for using rsplit" 2378 | }, 2379 | "split": { 2380 | "prefix": ".split", 2381 | "body": ".split()", 2382 | "description": "Splits the string at the specified separator, and returns a list" 2383 | }, 2384 | "string.split=>": { 2385 | "prefix": "string.split=>", 2386 | "body": [ 2387 | "txt = 'welcome to the jungle'", 2388 | "x = txt.split()", 2389 | "print(x)" 2390 | ], 2391 | "description": "An example for using split" 2392 | }, 2393 | "string.split=>": { 2394 | "prefix": "string.split=>", 2395 | "body": [ 2396 | "txt = 'hello, my name is Peter, I am 26 years old'", 2397 | "x = txt.split(', ')", 2398 | "print(x)" 2399 | ], 2400 | "description": "An example for using split" 2401 | }, 2402 | "string.split=>": { 2403 | "prefix": "string.split=>", 2404 | "body": [ 2405 | "txt = 'apple#banana#cherry#orange'", 2406 | "x = txt.split('#')", 2407 | "print(x)" 2408 | ], 2409 | "description": "An example for using split" 2410 | }, 2411 | "string.split=>": { 2412 | "prefix": "string.split=>", 2413 | "body": [ 2414 | "txt = 'apple#banana#cherry#orange'", 2415 | "# setting the max parameter to 1, will return a list with 2 elements!", 2416 | "x = txt.split('#', 1)", 2417 | "print(x)" 2418 | ], 2419 | "description": "An example for using split" 2420 | }, 2421 | "splitlines": { 2422 | "prefix": ".splitlines", 2423 | "body": ".splitlines()", 2424 | "description": "Splits the string at line breaks and returns a list" 2425 | }, 2426 | "string.splitlines=>": { 2427 | "prefix": "string.splitlines=>", 2428 | "body": [ 2429 | "txt = 'Thank you for the music\nWelcome to the jungle'", 2430 | "x = txt.splitlines()", 2431 | "print(x)" 2432 | ], 2433 | "description": "An example for using splitlines" 2434 | }, 2435 | "string.splitlines=>": { 2436 | "prefix": "string.splitlines=>", 2437 | "body": [ 2438 | "txt = 'Thank you for the music\nWelcome to the jungle'", 2439 | "x = txt.splitlines(True)", 2440 | "print(x)" 2441 | ], 2442 | "description": "An example for using splitlines" 2443 | }, 2444 | "startswith": { 2445 | "prefix": ".startswith", 2446 | "body": ".startswith()", 2447 | "description": "Returns true if the string starts with the specified value" 2448 | }, 2449 | "string.startswith=>": { 2450 | "prefix": "string.startswith=>", 2451 | "body": [ 2452 | "txt = 'Hello, welcome to my world.'", 2453 | "x = txt.startswith('Hello')", 2454 | "print(x)" 2455 | ], 2456 | "description": "An example for using startswith" 2457 | }, 2458 | "string.startswith=>": { 2459 | "prefix": "string.startswith=>", 2460 | "body": [ 2461 | "txt = 'Hello, welcome to my world.'", 2462 | "x = txt.startswith('wel', 7, 20)", 2463 | "print(x)" 2464 | ], 2465 | "description": "An example for using startswith" 2466 | }, 2467 | "swapcase": { 2468 | "prefix": ".swapcase", 2469 | "body": ".swapcase()", 2470 | "description": "Swaps cases, lower case becomes upper case and vice versa" 2471 | }, 2472 | "string.swapcase=>": { 2473 | "prefix": "string.swapcase=>", 2474 | "body": [ 2475 | "txt = 'Hello My Name Is PETER'", 2476 | "x = txt.swapcase()", 2477 | "print(x)" 2478 | ], 2479 | "description": "An example for using swapcase" 2480 | }, 2481 | "title": { 2482 | "prefix": ".title", 2483 | "body": ".title()", 2484 | "description": "Converts the first character of each word to upper case" 2485 | }, 2486 | "string.title=>": { 2487 | "prefix": "string.title=>", 2488 | "body": [ 2489 | "txt = 'Welcome to my world'", 2490 | "x = txt.title()", 2491 | "print(x)" 2492 | ], 2493 | "description": "An example for using title" 2494 | }, 2495 | "string.title=>": { 2496 | "prefix": "string.title=>", 2497 | "body": [ 2498 | "txt = 'Welcome to my 2nd world'", 2499 | "x = txt.title()", 2500 | "print(x)" 2501 | ], 2502 | "description": "An example for using title" 2503 | }, 2504 | "string.title=>": { 2505 | "prefix": "string.title=>", 2506 | "body": [ 2507 | "txt = 'hello b2b2b2 and 3g3g3g'", 2508 | "x = txt.title()", 2509 | "print(x)" 2510 | ], 2511 | "description": "An example for using title" 2512 | }, 2513 | "translate": { 2514 | "prefix": ".translate", 2515 | "body": ".translate()", 2516 | "description": "Returns a translated string" 2517 | }, 2518 | "string.translate=>": { 2519 | "prefix": "string.translate=>", 2520 | "body": [ 2521 | "# translation table - a dictionary", 2522 | "translation = {97: None, 98: None, 99: 105}", 2523 | "", 2524 | "string = 'abcdef'", 2525 | "print('Original string:', string)", 2526 | "", 2527 | "# translate string", 2528 | "print('Translated string:', string.translate(translation))" 2529 | ], 2530 | "description": "An example for using translate" 2531 | }, 2532 | "upper": { 2533 | "prefix": ".upper", 2534 | "body": ".upper()", 2535 | "description": "Converts a string into upper case" 2536 | }, 2537 | "string.upper=>": { 2538 | "prefix": "string.upper=>", 2539 | "body": [ 2540 | "txt = 'Hello my friends'", 2541 | "x = txt.upper()", 2542 | "print(x)" 2543 | ], 2544 | "description": "An example for using upper" 2545 | }, 2546 | "zfill": { 2547 | "prefix": ".zfill", 2548 | "body": ".zfill()", 2549 | "description": "Fills the string with a specified number of 0 values at the beginning" 2550 | }, 2551 | "string.zfill=>": { 2552 | "prefix": "string.zfill=>", 2553 | "body": [ 2554 | "txt = '50'", 2555 | "x = txt.zfill(10)", 2556 | "print(x)" 2557 | ], 2558 | "description": "An example for using zfill" 2559 | }, 2560 | "append": { 2561 | "prefix": ".append", 2562 | "body": ".append()", 2563 | "description": "Adds an element at the end of the list" 2564 | }, 2565 | "list.append=>": { 2566 | "prefix": "list.append=>", 2567 | "body": [ 2568 | "fruits = ['apple', 'banana', 'cherry']", 2569 | "fruits.append('orange')", 2570 | "print(fruits)" 2571 | ], 2572 | "description": "An example for using append" 2573 | }, 2574 | "list.append=>": { 2575 | "prefix": "list.append=>", 2576 | "body": [ 2577 | "a = ['apple', 'banana', 'cherry']", 2578 | "b = ['Ford', 'BMW', 'Volvo']", 2579 | "a.append(b)", 2580 | "print(a)" 2581 | ], 2582 | "description": "An example for using append" 2583 | }, 2584 | "clear": { 2585 | "prefix": ".clear", 2586 | "body": ".clear()", 2587 | "description": "Removes all the elements from the list" 2588 | }, 2589 | "list.clear=>": { 2590 | "prefix": "list.clear=>", 2591 | "body": [ 2592 | "fruits = ['apple', 'banana', 'cherry']", 2593 | "fruits.clear()", 2594 | "print(fruits)" 2595 | ], 2596 | "description": "An example for using clear" 2597 | }, 2598 | "copy": { 2599 | "prefix": ".copy", 2600 | "body": ".copy()", 2601 | "description": "Returns a copy of the list" 2602 | }, 2603 | "list.copy=>": { 2604 | "prefix": "list.copy=>", 2605 | "body": [ 2606 | "fruits = ['apple', 'banana', 'cherry']", 2607 | "x = fruits.copy()", 2608 | "print(x)" 2609 | ], 2610 | "description": "An example for using copy" 2611 | }, 2612 | "list.count": { 2613 | "prefix": ".count", 2614 | "body": ".count", 2615 | "description": "Returns the number of elements with the specified value" 2616 | }, 2617 | "list.count=>": { 2618 | "prefix": "list.count=>", 2619 | "body": [ 2620 | "fruits = ['apple', 'banana', 'cherry']", 2621 | "x = fruits.count('cherry')", 2622 | "print(x)" 2623 | ], 2624 | "description": "An example for using count" 2625 | }, 2626 | "list.count=>": { 2627 | "prefix": "list.count=>", 2628 | "body": [ 2629 | "fruits = [1, 4, 2, 9, 7, 8, 9, 3, 1]", 2630 | "x = fruits.count(9)", 2631 | "print(x)" 2632 | ], 2633 | "description": "An example for using count" 2634 | }, 2635 | "extend": { 2636 | "prefix": ".extend", 2637 | "body": ".extend()", 2638 | "description": "Add the elements of a list (or any iterable), to the end of the current list" 2639 | }, 2640 | "list.extend=>": { 2641 | "prefix": "list.extend=>", 2642 | "body": [ 2643 | "fruits = ['apple', 'banana', 'cherry']", 2644 | "points = (1, 4, 5, 9)", 2645 | "fruits.extend(points)", 2646 | "print(fruits)" 2647 | ], 2648 | "description": "An example for using extend" 2649 | }, 2650 | "index": { 2651 | "prefix": ".index", 2652 | "body": ".index()", 2653 | "description": "Returns the index of the first element with the specified value" 2654 | }, 2655 | "list.index=>": { 2656 | "prefix": "list.index=>", 2657 | "body": [ 2658 | "fruits = ['apple', 'banana', 'cherry']", 2659 | "x = fruits.index('cherry')", 2660 | "print(x)" 2661 | ], 2662 | "description": "An example for using index" 2663 | }, 2664 | "list.index=>": { 2665 | "prefix": "list.index=>", 2666 | "body": [ 2667 | "fruits = [4, 55, 64, 32, 16, 32]", 2668 | "x = fruits.index(32)", 2669 | "print(x)" 2670 | ], 2671 | "description": "An example for using index" 2672 | }, 2673 | "insert": { 2674 | "prefix": ".insert", 2675 | "body": ".insert()", 2676 | "description": "Adds an element at the specified position" 2677 | }, 2678 | "list.insert=>": { 2679 | "prefix": "list.insert=>", 2680 | "body": [ 2681 | "fruits = ['apple', 'banana', 'cherry']", 2682 | "x = fruits.insert(1, 'orange')", 2683 | "print(x)" 2684 | ], 2685 | "description": "An example for using insert" 2686 | }, 2687 | "pop": { 2688 | "prefix": ".pop", 2689 | "body": ".pop()", 2690 | "description": "Removes the element at the specified position" 2691 | }, 2692 | "list.pop=>": { 2693 | "prefix": "list.pop=>", 2694 | "body": [ 2695 | "fruits = ['apple', 'banana', 'cherry']", 2696 | "fruits.pop(1)", 2697 | "print(fruits)" 2698 | ], 2699 | "description": "An example for using pop" 2700 | }, 2701 | "remove": { 2702 | "prefix": ".remove", 2703 | "body": ".remove()", 2704 | "description": "Removes the first item with the specified value" 2705 | }, 2706 | "list.remove=>": { 2707 | "prefix": "list.remove=>", 2708 | "body": [ 2709 | "fruits = ['apple', 'banana', 'cherry']", 2710 | "fruits.remove('banana')", 2711 | "print(fruits)" 2712 | ], 2713 | "description": "An example for using remove" 2714 | }, 2715 | "reverse": { 2716 | "prefix": ".reverse", 2717 | "body": ".reverse()", 2718 | "description": "Reverses the order of the list" 2719 | }, 2720 | "list.reverse=>": { 2721 | "prefix": "list.reverse=>", 2722 | "body": [ 2723 | "fruits = ['apple', 'banana', 'cherry']", 2724 | "fruits.reverse()", 2725 | "print(fruits)" 2726 | ], 2727 | "description": "An example for using reverse" 2728 | }, 2729 | "sort": { 2730 | "prefix": ".sort", 2731 | "body": ".sort()", 2732 | "description": "Sorts the list" 2733 | }, 2734 | "list.sort=>": { 2735 | "prefix": "list.sort=>", 2736 | "body": [ 2737 | "cars = ['Ford', 'BMW', 'Volvo']", 2738 | "cars.sort()", 2739 | "print(cars)" 2740 | ], 2741 | "description": "An example for using sort" 2742 | }, 2743 | "list.sort=>": { 2744 | "prefix": "list.sort=>", 2745 | "body": [ 2746 | "cars = ['Ford', 'BMW', 'Volvo']", 2747 | "cars.sort(reverse=True)", 2748 | "print(cars)" 2749 | ], 2750 | "description": "An example for using sort" 2751 | }, 2752 | "list.sort=>": { 2753 | "prefix": "list.sort=>", 2754 | "body": [ 2755 | "# A function that returns the length of the value:", 2756 | "def myFunc(e):", 2757 | " return len(e)", 2758 | "cars = ['Ford', 'Mitsubishi', 'BMW', 'VW']", 2759 | "cars.sort(key=myFunc)", 2760 | "print(cars)" 2761 | ], 2762 | "description": "An example for using sort" 2763 | }, 2764 | "list.sort=>": { 2765 | "prefix": "list.sort=>", 2766 | "body": [ 2767 | "# A function that returns the length of the value:", 2768 | "def myFunc(e):", 2769 | " return len(e)", 2770 | "cars = ['Ford', 'Mitsubishi', 'BMW', 'VW']", 2771 | "cars.sort(reverse=True, key=myFunc)", 2772 | "print(cars)" 2773 | ], 2774 | "description": "An example for using sort" 2775 | }, 2776 | "comprehensions": { 2777 | "prefix": "comp=>", 2778 | "body": "[ expression for item in list if conditional ]", 2779 | "description": "List Comprehensions" 2780 | }, 2781 | "list.comp=>_1": { 2782 | "prefix": "list.comp=>_1", 2783 | "body": [ 2784 | "x = [i for i in range(10)]", 2785 | "print(x)" 2786 | ], 2787 | "description": "An example for using list comprehension" 2788 | }, 2789 | "list.comp=>_2": { 2790 | "prefix": "list.comp=>_2", 2791 | "body": [ 2792 | "x = [x**2 for x in range(10)]", 2793 | "print(x)" 2794 | ], 2795 | "description": "An example for using list comprehension" 2796 | }, 2797 | "list.comp=>_3": { 2798 | "prefix": "list.comp=>_3", 2799 | "body": [ 2800 | "list1 = [3,4,5]", 2801 | "multiplied = [item*3 for item in list1]", 2802 | "print(multiplied)" 2803 | ], 2804 | "description": "An example for using list comprehension" 2805 | }, 2806 | "list.comp=>_4": { 2807 | "prefix": "list.comp=>_4", 2808 | "body": [ 2809 | "listOfWords = ['this','is','a','list','of','words']", 2810 | "items = [ word[0] for word in listOfWords ]", 2811 | "print(items)" 2812 | ], 2813 | "description": "An example for using list comprehension" 2814 | }, 2815 | "list.comp=>_5": { 2816 | "prefix": "list.comp=>_5", 2817 | "body": [ 2818 | "x = [double(x) for x in range(10) if x%2==0]", 2819 | "print(x)" 2820 | ], 2821 | "description": "An example for using list comprehension" 2822 | }, 2823 | "clear": { 2824 | "prefix": ".clear", 2825 | "body": ".clear()", 2826 | "description": "Removes all the elements from the dictionary" 2827 | }, 2828 | "dictionary.clear=>": { 2829 | "prefix": "dictionary.clear=>", 2830 | "body": [ 2831 | "car = {", 2832 | " 'brand': 'Ford',", 2833 | " 'model': 'Mustang',", 2834 | " 'year': 1964", 2835 | "}", 2836 | "car.clear()", 2837 | "print(car)" 2838 | ], 2839 | "description": "An example for using clear" 2840 | }, 2841 | "copy": { 2842 | "prefix": ".copy", 2843 | "body": ".copy()", 2844 | "description": "Returns a copy of the dictionary" 2845 | }, 2846 | "dictionary.copy=>": { 2847 | "prefix": "dictionary.copy=>", 2848 | "body": [ 2849 | "car = {", 2850 | " 'brand': 'Ford',", 2851 | " 'model': 'Mustang',", 2852 | " 'year': 1964", 2853 | "}", 2854 | "x = car.copy()", 2855 | "print(x)" 2856 | ], 2857 | "description": "An example for using copy" 2858 | }, 2859 | "fromkeys": { 2860 | "prefix": ".fromkeys", 2861 | "body": ".fromkeys(x, y)", 2862 | "description": "Returns a dictionary with the specified keys and values" 2863 | }, 2864 | "dictionary.fromkeys=>": { 2865 | "prefix": "dictionary.fromkeys=>", 2866 | "body": [ 2867 | "x = ('key1', 'key2', 'key3')", 2868 | "y = 0", 2869 | "thisdict = dict.fromkeys(x, y)", 2870 | "print(thisdict)" 2871 | ], 2872 | "description": "An example for using fromkeys" 2873 | }, 2874 | "dictionary.fromkeys=>": { 2875 | "prefix": "dictionary.fromkeys=>", 2876 | "body": [ 2877 | "x = ('key1', 'key2', 'key3')", 2878 | "thisdict = dict.fromkeys(x)", 2879 | "print(thisdict)" 2880 | ], 2881 | "description": "An example for using fromkeys" 2882 | }, 2883 | "get": { 2884 | "prefix": ".get", 2885 | "body": ".get()", 2886 | "description": "Returns the value of the specified key" 2887 | }, 2888 | "dictionary.get=>": { 2889 | "prefix": "dictionary.get=>", 2890 | "body": [ 2891 | "car = {", 2892 | " 'brand': 'Ford',", 2893 | " 'model': 'Mustang',", 2894 | " 'year': 1964", 2895 | "}", 2896 | "x = car.get('model')", 2897 | "print(x)" 2898 | ], 2899 | "description": "An example for using get" 2900 | }, 2901 | "dictionary.get=>": { 2902 | "prefix": "dictionary.get=>", 2903 | "body": [ 2904 | "car = {", 2905 | " 'brand': 'Ford',", 2906 | " 'model': 'Mustang',", 2907 | " 'year': 1964", 2908 | "}", 2909 | "x = car.get('price', 15000)", 2910 | "print(x)" 2911 | ], 2912 | "description": "An example for using get" 2913 | }, 2914 | "items": { 2915 | "prefix": ".items", 2916 | "body": ".items()", 2917 | "description": "Returns a list containing the a tuple for each key value pair" 2918 | }, 2919 | "dictionary.items=>": { 2920 | "prefix": "dictionary.items=>", 2921 | "body": [ 2922 | "car = {", 2923 | " 'brand': 'Ford',", 2924 | " 'model': 'Mustang',", 2925 | " 'year': 1964", 2926 | "}", 2927 | "x = car.items()", 2928 | "print(x)" 2929 | ], 2930 | "description": "An example for using items" 2931 | }, 2932 | "dictionary.items=>": { 2933 | "prefix": "dictionary.items=>", 2934 | "body": [ 2935 | "car = {", 2936 | " 'brand': 'Ford',", 2937 | " 'model': 'Mustang',", 2938 | " 'year': 1964", 2939 | "}", 2940 | "x = car.items()", 2941 | "car['year'] = 2018", 2942 | "print(x)" 2943 | ], 2944 | "description": "An example for using items" 2945 | }, 2946 | "keys": { 2947 | "prefix": ".keys", 2948 | "body": ".keys()", 2949 | "description": "Returns a list containing the dictionary's keys" 2950 | }, 2951 | "dictionary.keys=>": { 2952 | "prefix": "dictionary.keys=>", 2953 | "body": [ 2954 | "car = {", 2955 | " 'brand': 'Ford',", 2956 | " 'model': 'Mustang',", 2957 | " 'year': 1964", 2958 | "}", 2959 | "x = car.keys()", 2960 | "print(x)" 2961 | ], 2962 | "description": "An example for using keys" 2963 | }, 2964 | "dictionary.keys=>": { 2965 | "prefix": "dictionary.keys=>", 2966 | "body": [ 2967 | "car = {", 2968 | " 'brand': 'Ford',", 2969 | " 'model': 'Mustang',", 2970 | " 'year': 1964", 2971 | "}", 2972 | "x = car.keys()", 2973 | "car['color'] = 'white'", 2974 | "print(x)" 2975 | ], 2976 | "description": "An example for using keys" 2977 | }, 2978 | "pop": { 2979 | "prefix": ".pop", 2980 | "body": ".pop()", 2981 | "description": "Removes the element with the specified key" 2982 | }, 2983 | "dictionary.pop=>": { 2984 | "prefix": "dictionary.pop=>", 2985 | "body": [ 2986 | "car = {", 2987 | " 'brand': 'Ford',", 2988 | " 'model': 'Mustang',", 2989 | " 'year': 1964", 2990 | "}", 2991 | "car.pop('model')", 2992 | "print(car)" 2993 | ], 2994 | "description": "An example for using pop" 2995 | }, 2996 | "popitem": { 2997 | "prefix": ".popitem", 2998 | "body": ".popitem()", 2999 | "description": "Removes the last inserted key-value pai" 3000 | }, 3001 | "dictionary.popitem=>": { 3002 | "prefix": "dictionary.popitem=>", 3003 | "body": [ 3004 | "car = {", 3005 | " 'brand': 'Ford',", 3006 | " 'model': 'Mustang',", 3007 | " 'year': 1964", 3008 | "}", 3009 | "car.popitem()", 3010 | "print(car)" 3011 | ], 3012 | "description": "An example for using popitem" 3013 | }, 3014 | "setdefault": { 3015 | "prefix": ".setdefault", 3016 | "body": ".setdefault()", 3017 | "description": "Returns the value of the specified key. If the key does not exist: insert the key, with the specified value" 3018 | }, 3019 | "dictionary.setdefault=>": { 3020 | "prefix": "dictionary.setdefault=>", 3021 | "body": [ 3022 | "car = {", 3023 | " 'brand': 'Ford',", 3024 | " 'model': 'Mustang',", 3025 | " 'year': 1964", 3026 | "}", 3027 | "x = car.setdefault('model', 'Bronco')", 3028 | "print(x)" 3029 | ], 3030 | "description": "An example for using setdefault" 3031 | }, 3032 | "dictionary.setdefault=>": { 3033 | "prefix": "dictionary.setdefault=>", 3034 | "body": [ 3035 | "car = {", 3036 | " 'brand': 'Ford',", 3037 | " 'model': 'Mustang',", 3038 | " 'year': 1964", 3039 | "}", 3040 | "x = car.setdefault('color', 'white')", 3041 | "print(x)" 3042 | ], 3043 | "description": "An example for using setdefault" 3044 | }, 3045 | "update": { 3046 | "prefix": ".update", 3047 | "body": ".update()", 3048 | "description": "Updates the dictionary with the specified key-value pairs" 3049 | }, 3050 | "dictionary.update=>": { 3051 | "prefix": "dictionary.update=>", 3052 | "body": [ 3053 | "car = {", 3054 | " 'brand': 'Ford',", 3055 | " 'model': 'Mustang',", 3056 | " 'year': 1964", 3057 | "}", 3058 | "car.update({'color': 'White'})", 3059 | "print(car)" 3060 | ], 3061 | "description": "An example for using update" 3062 | }, 3063 | "values": { 3064 | "prefix": ".values", 3065 | "body": ".values()", 3066 | "description": "Returns a list of all the values in the dictionary" 3067 | }, 3068 | "dictionary.values=>": { 3069 | "prefix": "dictionary.values=>", 3070 | "body": [ 3071 | "car = {", 3072 | " 'brand': 'Ford',", 3073 | " 'model': 'Mustang',", 3074 | " 'year': 1964", 3075 | "}", 3076 | "x = car.values()", 3077 | "print(x)" 3078 | ], 3079 | "description": "An example for using values" 3080 | }, 3081 | "dictionary.values=>": { 3082 | "prefix": "dictionary.values=>", 3083 | "body": [ 3084 | "car = {", 3085 | " 'brand': 'Ford',", 3086 | " 'model': 'Mustang',", 3087 | " 'year': 1964", 3088 | "}", 3089 | "x = car.values()", 3090 | "car['year'] = 2018", 3091 | "print(x)" 3092 | ], 3093 | "description": "An example for using values" 3094 | }, 3095 | "tuple.count": { 3096 | "prefix": ".count", 3097 | "body": ".count(value)", 3098 | "description": "Returns the number of times a specified value occurs in a tuple" 3099 | }, 3100 | "tuple.count=>": { 3101 | "prefix": "tuple.count=>", 3102 | "body": [ 3103 | "thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)", 3104 | "x = thistuple.count(5)", 3105 | "print(x)" 3106 | ], 3107 | "description": "An example for using count" 3108 | }, 3109 | "index": { 3110 | "prefix": ".index", 3111 | "body": ".index(value)", 3112 | "description": "Searches the tuple for a specified value and returns the position of where it was found" 3113 | }, 3114 | "tuple.index=>": { 3115 | "prefix": "tuple.index=>", 3116 | "body": [ 3117 | "thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)", 3118 | "x = thistuple.index(8)", 3119 | "print(x)" 3120 | ], 3121 | "description": "An example for using index" 3122 | }, 3123 | "add": { 3124 | "prefix": ".add", 3125 | "body": ".add()", 3126 | "description": "Adds an element to the set" 3127 | }, 3128 | "sets.add=>": { 3129 | "prefix": "sets.add=>", 3130 | "body": [ 3131 | "fruits = {'apple', 'banana', 'cherry'}", 3132 | "fruits.add('orange') ", 3133 | "print(fruits)" 3134 | ], 3135 | "description": "An example for using add" 3136 | }, 3137 | "clear": { 3138 | "prefix": ".clear", 3139 | "body": ".clear()", 3140 | "description": "Removes all the elements from the set" 3141 | }, 3142 | "sets.clear=>": { 3143 | "prefix": "sets.clear=>", 3144 | "body": [ 3145 | "fruits = {'apple', 'banana', 'cherry'}", 3146 | "fruits.clear()", 3147 | "print(fruits)" 3148 | ], 3149 | "description": "An example for using clear" 3150 | }, 3151 | "copy": { 3152 | "prefix": ".copy", 3153 | "body": ".copy()", 3154 | "description": "Returns a copy of the set" 3155 | }, 3156 | "sets.copy=>": { 3157 | "prefix": "sets.copy=>", 3158 | "body": [ 3159 | "fruits = {'apple', 'banana', 'cherry'}", 3160 | "x = fruits.copy()", 3161 | "print(x)" 3162 | ], 3163 | "description": "An example for using copy" 3164 | }, 3165 | "difference": { 3166 | "prefix": ".difference", 3167 | "body": "x.difference(y)", 3168 | "description": "Returns a set containing the difference between two or more sets" 3169 | }, 3170 | "sets.difference=>_1": { 3171 | "prefix": "sets.difference=>_1", 3172 | "body": [ 3173 | "x = {'apple', 'banana', 'cherry'}", 3174 | "y = {'google', 'microsoft', 'apple'}", 3175 | "z = x.difference(y)", 3176 | "print(z)" 3177 | ], 3178 | "description": "An example for using difference" 3179 | }, 3180 | "sets.difference=>_2": { 3181 | "prefix": "sets.difference=>_2", 3182 | "body": [ 3183 | "x = {'apple', 'banana', 'cherry'}", 3184 | "y = {'google', 'microsoft', 'apple'}", 3185 | "z = y.difference(x) ", 3186 | "print(z)" 3187 | ], 3188 | "description": "An example for using difference" 3189 | }, 3190 | "difference_update": { 3191 | "prefix": ".difference_update", 3192 | "body": "x.difference_update(y)", 3193 | "description": "Removes the items in this set that are also included in another, specified set" 3194 | }, 3195 | "sets.difference_update=>": { 3196 | "prefix": "sets.difference_update=>", 3197 | "body": [ 3198 | "x = {'apple', 'banana', 'cherry'}", 3199 | "y = {'google', 'microsoft', 'apple'}", 3200 | "x.difference_update(y)", 3201 | "print(x)" 3202 | ], 3203 | "description": "An example for using difference_update" 3204 | }, 3205 | "discard": { 3206 | "prefix": ".discard", 3207 | "body": ".discard()", 3208 | "description": "Remove the specified item" 3209 | }, 3210 | "sets.discard=>": { 3211 | "prefix": "sets.discard=>", 3212 | "body": [ 3213 | "fruits = {'apple', 'banana', 'cherry'}", 3214 | "fruits.discard('banana') ", 3215 | "print(fruits)" 3216 | ], 3217 | "description": "An example for using discard" 3218 | }, 3219 | "intersection": { 3220 | "prefix": ".intersection", 3221 | "body": "x.intersection(y)", 3222 | "description": "Returns a set, that is the intersection of two other sets" 3223 | }, 3224 | "sets.intersection=>_1": { 3225 | "prefix": "sets.intersection=>_1", 3226 | "body": [ 3227 | "x = {'apple', 'banana', 'cherry'}", 3228 | "y = {'google', 'microsoft', 'apple'}", 3229 | "z = x.intersection(y)", 3230 | "print(z)" 3231 | ], 3232 | "description": "An example for using intersection" 3233 | }, 3234 | "sets.intersection=>_2": { 3235 | "prefix": "sets.intersection=>_2", 3236 | "body": [ 3237 | "x = {'a', 'b', 'c'}", 3238 | "y = {'c', 'd', 'e'}", 3239 | "z = {'f', 'g', 'c'}", 3240 | "result = x.intersection(y, z)", 3241 | "print(result)" 3242 | ], 3243 | "description": "An example for using intersection" 3244 | }, 3245 | "intersection_update": { 3246 | "prefix": ".intersection_update", 3247 | "body": "x.intersection_update(y)", 3248 | "description": "Removes the items in this set that are not present in other, specified set(s)" 3249 | }, 3250 | "sets.intersection_update=>_1": { 3251 | "prefix": "sets.intersection_update=>_1", 3252 | "body": [ 3253 | "x = {'apple', 'banana', 'cherry'}", 3254 | "y = {'google', 'microsoft', 'apple'}", 3255 | "x.intersection_update(y)", 3256 | "print(x)" 3257 | ], 3258 | "description": "An example for using intersection_update" 3259 | }, 3260 | "sets.intersection_update=>_2": { 3261 | "prefix": "sets.intersection_update=>_2", 3262 | "body": [ 3263 | "x = {'a', 'b', 'c'}", 3264 | "y = {'c', 'd', 'e'}", 3265 | "z = {'f', 'g', 'c'}", 3266 | "x.intersection_update(y, z)", 3267 | "print(x)" 3268 | ], 3269 | "description": "An example for using intersection_update" 3270 | }, 3271 | "isdisjoint": { 3272 | "prefix": ".isdisjoint", 3273 | "body": "x.isdisjoint(y)", 3274 | "description": "Returns whether two sets have a intersection or not" 3275 | }, 3276 | "sets.isdisjoint=>_1": { 3277 | "prefix": "sets.isdisjoint=>_1", 3278 | "body": [ 3279 | "x = {'apple', 'banana', 'cherry'}", 3280 | "y = {'google', 'microsoft', 'facebook'}", 3281 | "z = ", 3282 | "print(z)" 3283 | ], 3284 | "description": "An example for using isdisjoint" 3285 | }, 3286 | "sets.isdisjoint=>_2": { 3287 | "prefix": "sets.isdisjoint=>_2", 3288 | "body": [ 3289 | "x = {'apple', 'banana', 'cherry'}", 3290 | "y = {'google', 'microsoft', 'apple'}", 3291 | "z = x.isdisjoint(y) ", 3292 | "print(z)" 3293 | ], 3294 | "description": "An example for using isdisjoint" 3295 | }, 3296 | "issubset": { 3297 | "prefix": ".issubset", 3298 | "body": "x.issubset(y)", 3299 | "description": "Returns whether another set contains this set or not" 3300 | }, 3301 | "sets.issubset=>_1": { 3302 | "prefix": "sets.sets.issubset=>_1", 3303 | "body": [ 3304 | "x = {'a', 'b', 'c'}", 3305 | "y = {'f', 'e', 'd', 'c', 'b', 'a'}", 3306 | "z = x.issubset(y) ", 3307 | "print(z)" 3308 | ], 3309 | "description": "An example for using issubset" 3310 | }, 3311 | "sets.issubset=>_2": { 3312 | "prefix": "sets.issubset=>_2", 3313 | "body": [ 3314 | "x = {'a', 'b', 'c'}", 3315 | "y = {'f', 'e', 'd', 'c', 'b'}", 3316 | "z = x.issubset(y) ", 3317 | "print(z)" 3318 | ], 3319 | "description": "An example for using issubset" 3320 | }, 3321 | "issuperset": { 3322 | "prefix": ".issuperset", 3323 | "body": "x.issuperset(y)", 3324 | "description": "Returns whether this set contains another set or not" 3325 | }, 3326 | "sets.issuperset=>_1": { 3327 | "prefix": "sets.issuperset=>_1", 3328 | "body": [ 3329 | "x = {'f', 'e', 'd', 'c', 'b', 'a'}", 3330 | "y = {'a', 'b', 'c'}", 3331 | "z = x.issuperset(y) ", 3332 | "print(z)" 3333 | ], 3334 | "description": "An example for using issuperset" 3335 | }, 3336 | "sets.issuperset=>_2": { 3337 | "prefix": "sets.issuperset=>_2", 3338 | "body": [ 3339 | "x = {'f', 'e', 'd', 'c', 'b'}", 3340 | "y = {'a', 'b', 'c'}", 3341 | "z = x.issuperset(y) ", 3342 | "print(z)" 3343 | ], 3344 | "description": "An example for using issuperset" 3345 | }, 3346 | "pop": { 3347 | "prefix": ".pop", 3348 | "body": ".pop()", 3349 | "description": "Removes the specified element" 3350 | }, 3351 | "sets.pop=>": { 3352 | "prefix": "sets.pop=>", 3353 | "body": [ 3354 | "fruits = {'apple', 'banana', 'cherry'}", 3355 | "fruits.pop() ", 3356 | "print(fruits)" 3357 | ], 3358 | "description": "An example for using pop" 3359 | }, 3360 | "remove": { 3361 | "prefix": ".remove", 3362 | "body": ".remove()", 3363 | "description": "Removes the specified element" 3364 | }, 3365 | "sets.remove=>": { 3366 | "prefix": "sets.remove=>", 3367 | "body": [ 3368 | "fruits = {'apple', 'banana', 'cherry'}", 3369 | "fruits.remove('banana') ", 3370 | "print(fruits)" 3371 | ], 3372 | "description": "An example for using remove" 3373 | }, 3374 | "symmetric_difference": { 3375 | "prefix": ".symmetric_difference", 3376 | "body": "x.symmetric_difference(y)", 3377 | "description": "Returns a set with the symmetric differences of two sets" 3378 | }, 3379 | "sets.symmetric_difference=>": { 3380 | "prefix": "sets.symmetric_difference=>", 3381 | "body": [ 3382 | "x = {'apple', 'banana', 'cherry'}", 3383 | "y = {'google', 'microsoft', 'apple'}", 3384 | "z = x.symmetric_difference(y) ", 3385 | "print(z)" 3386 | ], 3387 | "description": "An example for using symmetric_difference" 3388 | }, 3389 | "symmetric_difference_update": { 3390 | "prefix": ".symmetric_difference_update", 3391 | "body": "x.symmetric_difference_update(y)", 3392 | "description": "inserts the symmetric differences from this set and another" 3393 | }, 3394 | "sets.symmetric_difference_update=>": { 3395 | "prefix": "sets.symmetric_difference_update=>", 3396 | "body": [ 3397 | "x = {'apple', 'banana', 'cherry'}", 3398 | "y = {'google', 'microsoft', 'apple'}", 3399 | "x.symmetric_difference_update(y) ", 3400 | "print(x)" 3401 | ], 3402 | "description": "An example for using symmetric_difference_update" 3403 | }, 3404 | "union": { 3405 | "prefix": ".union", 3406 | "body": "x.union(y)", 3407 | "description": "Return a set containing the union of sets" 3408 | }, 3409 | "sets.union=>_1": { 3410 | "prefix": "sets.union=>_1", 3411 | "body": [ 3412 | "x = {'apple', 'banana', 'cherry'}", 3413 | "y = {'google', 'microsoft', 'apple'}", 3414 | "z = x.union(y) ", 3415 | "print(z)" 3416 | ], 3417 | "description": "An example for using union" 3418 | }, 3419 | "sets.union=>_2": { 3420 | "prefix": "sets.union=>_2", 3421 | "body": [ 3422 | "x = {'a', 'b', 'c'}", 3423 | "y = {'f', 'd', 'a'}", 3424 | "z = {'c', 'd', 'e'}", 3425 | "result = x.union(y, z) ", 3426 | "print(result)" 3427 | ], 3428 | "description": "An example for using union" 3429 | }, 3430 | "update": { 3431 | "prefix": ".update", 3432 | "body": "x.update(y)", 3433 | "description": "Update the set with the union of this set and others" 3434 | }, 3435 | "sets.update=>": { 3436 | "prefix": "sets.update=>", 3437 | "body": [ 3438 | "x = {'apple', 'banana', 'cherry'}", 3439 | "y = {'google', 'microsoft', 'apple'}", 3440 | "x.update(y) ", 3441 | "print(x)" 3442 | ], 3443 | "description": "An example for using update" 3444 | }, 3445 | "class": { 3446 | "prefix": "class=>", 3447 | "body": [ 3448 | "class MyClass:", 3449 | " pass" 3450 | ], 3451 | "description": "python class" 3452 | }, 3453 | "__init__": { 3454 | "prefix": "__init__=>", 3455 | "body": [ 3456 | "def __init__(self, name, age):", 3457 | " self.name = name", 3458 | " self.age = age" 3459 | ], 3460 | "description": "__init__ method" 3461 | }, 3462 | "__iter__": { 3463 | "prefix": "__iter__=>", 3464 | "body": [ 3465 | "def __iter__(self):", 3466 | " self.a = 1", 3467 | " return self" 3468 | ], 3469 | "description": "__iter__ method" 3470 | }, 3471 | "__next__": { 3472 | "prefix": "__next__=>", 3473 | "body": [ 3474 | "def __next__(self):", 3475 | " x = self.a", 3476 | " self.a += 1", 3477 | " return x" 3478 | ], 3479 | "description": "__next__ method" 3480 | }, 3481 | "import": { 3482 | "prefix": "import=>", 3483 | "body": "import mymodule as mx", 3484 | "description": "import module" 3485 | }, 3486 | "tryexcept": { 3487 | "prefix": "trye=>", 3488 | "body": [ 3489 | "try:", 3490 | " print(x)", 3491 | "except:", 3492 | " print('An exception occurred')" 3493 | ], 3494 | "description": "tryexcept method" 3495 | }, 3496 | "tryexceptfinally": { 3497 | "prefix": "tryef=>", 3498 | "body": [ 3499 | "try:", 3500 | " print(x)", 3501 | "except:", 3502 | " print('Something went wrong')", 3503 | "finally:", 3504 | " print('The try except is finished')" 3505 | ], 3506 | "description": "tryexceptfinally method" 3507 | }, 3508 | "openFile": { 3509 | "prefix": "file=>openFile", 3510 | "body": [ 3511 | "f = open('demofile.txt', 'r')", 3512 | "print(f.read())" 3513 | ], 3514 | "description": "open a file" 3515 | }, 3516 | "openFileReadLine": { 3517 | "prefix": "file=>openFileReadLine", 3518 | "body": [ 3519 | "f = open('demofile.txt', 'r')", 3520 | "print(f.readline())" 3521 | ], 3522 | "description": "Read one line of the file" 3523 | }, 3524 | "writeExistFile": { 3525 | "prefix": "file=>writeExistFile", 3526 | "body": [ 3527 | "f = open('demofile.txt', 'a')", 3528 | "f.write('Now the file has one more line!')" 3529 | ], 3530 | "description": "Write to an Existing File" 3531 | }, 3532 | "writeOwerWrite": { 3533 | "prefix": "file=>writeOwerWrite", 3534 | "body": [ 3535 | "f = open('demofile.txt', 'w')", 3536 | "f.write('Woops! I have deleted the content!')" 3537 | ], 3538 | "description": "Open a file and overwrite the content" 3539 | }, 3540 | "createFileIfDoesNotExist": { 3541 | "prefix": "file=>createFileIfDoesNotExist", 3542 | "body": "f = open('myfile.txt', 'w')", 3543 | "description": "Create a new file if it does not exist" 3544 | }, 3545 | "createFile": { 3546 | "prefix": "file=>createFile", 3547 | "body": "f = open('myfile.txt', 'x')", 3548 | "description": "Create a new file" 3549 | }, 3550 | "deleteFile": { 3551 | "prefix": "file=>deleteFile", 3552 | "body": [ 3553 | "#import os", 3554 | "os.remove('demofile.txt')" 3555 | ], 3556 | "description": "delete a file" 3557 | }, 3558 | "class=>_1": { 3559 | "prefix": "class=>_1", 3560 | "body": [ 3561 | "class Person:", 3562 | " pass # An empty block", 3563 | "p = Person()", 3564 | "print(p)" 3565 | ], 3566 | "description": "oop inheritance example" 3567 | }, 3568 | "class=>inheritance_1": { 3569 | "prefix": "class=>inheritance_1", 3570 | "body": [ 3571 | "class Bird:", 3572 | "", 3573 | " def __init__(self):", 3574 | " print('Bird is ready')", 3575 | "", 3576 | " def whoisThis(self):", 3577 | " print('Bird')", 3578 | "", 3579 | " def swim(self):", 3580 | " print('Swim faster')", 3581 | "", 3582 | "# child class", 3583 | "class Penguin(Bird):", 3584 | "", 3585 | " def __init__(self):", 3586 | " # call super() function", 3587 | " super().__init__()", 3588 | " print('Penguin is ready')", 3589 | "", 3590 | " def whoisThis(self):", 3591 | " print('Penguin')", 3592 | "", 3593 | " def run(self):", 3594 | " print('Run faster')", 3595 | "", 3596 | "peggy = Penguin()", 3597 | "peggy.whoisThis()", 3598 | "peggy.swim()", 3599 | "peggy.run()" 3600 | ], 3601 | "description": "oop inheritance example" 3602 | }, 3603 | "class=>inheritance_2": { 3604 | "prefix": "class=>inheritance_2", 3605 | "body": [ 3606 | "class SchoolMember:", 3607 | " '''Represents any school member.'''", 3608 | " def __init__(self, name, age):", 3609 | " self.name = name", 3610 | " self.age = age", 3611 | " print('(Initialized SchoolMember: {})'.format(self.name))", 3612 | " def tell(self):", 3613 | " '''Tell my details.'''", 3614 | " print('Name:{} Age:{}'.format(self.name, self.age), end=' ')", 3615 | "class Teacher(SchoolMember):", 3616 | " '''Represents a teacher.'''", 3617 | " def __init__(self, name, age, salary):", 3618 | " SchoolMember.__init__(self, name, age)", 3619 | " self.salary = salary", 3620 | " print('(Initialized Teacher: {})'.format(self.name))", 3621 | " def tell(self):", 3622 | " SchoolMember.tell(self)", 3623 | " print('Salary: {:d}'.format(self.salary))", 3624 | "class Student(SchoolMember):", 3625 | " '''Represents a student.'''", 3626 | " def __init__(self, name, age, marks):", 3627 | " SchoolMember.__init__(self, name, age)", 3628 | " self.marks = marks", 3629 | " print('(Initialized Student: {})'.format(self.name))", 3630 | " def tell(self):", 3631 | " SchoolMember.tell(self)", 3632 | " print('Marks: {:d}'.format(self.marks))", 3633 | "t = Teacher('Mrs. Shrividya', 40, 30000)", 3634 | "s = Student('Swaroop', 25, 75)", 3635 | "# prints a blank line", 3636 | "print()", 3637 | "members = [t, s]", 3638 | "for member in members:", 3639 | " # Works for both Teachers and Students", 3640 | " member.tell()" 3641 | ], 3642 | "description": "oop inheritance example" 3643 | }, 3644 | "class=>with_attribute_1": { 3645 | "prefix": "class=>with_attribute_1", 3646 | "body": [ 3647 | "class Parrot:", 3648 | "", 3649 | "# class attribute", 3650 | " species = 'bird'", 3651 | "", 3652 | "# instance attribute", 3653 | " def __init__(self, name, age):", 3654 | " self.name = name", 3655 | " self.age = age", 3656 | "", 3657 | "# instantiate the Parrot class", 3658 | "blu = Parrot('Blu', 10)", 3659 | "woo = Parrot('woo', 15)", 3660 | "", 3661 | "# access the class attributes", 3662 | "print('Blu is a {}'.format(blu.__class__.species))", 3663 | "print('Woo is also a {}'.format(woo.__class__.species))", 3664 | "# access the instance attributes", 3665 | "print('{} is {} years old'.format( blu.name, blu.age))", 3666 | "print('{} is {} years old'.format( woo.name, woo.age))" 3667 | ], 3668 | "description": "class with attribute example" 3669 | }, 3670 | "class=>with_attribute_2": { 3671 | "prefix": "class=>with_attribute_2", 3672 | "body": [ 3673 | "class Person:", 3674 | " def __init__(self, name):", 3675 | " self.name = name", 3676 | " def say_hi(self):", 3677 | " print('Hello, my name is', self.name)", 3678 | "p = Person('Swaroop')", 3679 | "p.say_hi()", 3680 | "# The previous 2 lines can also be written as", 3681 | "# Person('Swaroop').say_hi()" 3682 | ], 3683 | "description": "class with attribute example" 3684 | }, 3685 | "class=>with_attribute_3": { 3686 | "prefix": "class=>with_attribute_3", 3687 | "body": [ 3688 | "class Robot:", 3689 | " '''Represents a robot, with a name.'''", 3690 | " # A class variable, counting the number of robots", 3691 | " population = 0", 3692 | " def __init__(self, name):", 3693 | " '''Initializes the data.'''", 3694 | " self.name = name", 3695 | " print('(Initializing {})'.format(self.name))", 3696 | " # When this person is created, the robot", 3697 | " # adds to the population", 3698 | " Robot.population += 1", 3699 | " def die(self):", 3700 | " '''I am dying.'''", 3701 | " print('{} is being destroyed!'.format(self.name))", 3702 | " Robot.population -= 1", 3703 | " if Robot.population == 0:", 3704 | " print('{} was the last one.'.format(self.name))", 3705 | " else:", 3706 | " print('There are still {:d} robots working.'.format(", 3707 | " Robot.population))", 3708 | " def say_hi(self):", 3709 | " '''Greeting by the robot.", 3710 | " Yeah, they can do that.'''", 3711 | " print('Greetings, my masters call me {}.'.format(self.name))", 3712 | " @classmethod", 3713 | " def how_many(cls):", 3714 | " '''Prints the current population.'''", 3715 | " print('We have {:d} robots.'.format(cls.population))", 3716 | "droid1 = Robot('R2-D2')", 3717 | "droid1.say_hi()", 3718 | "Robot.how_many()", 3719 | "droid2 = Robot('C-3PO')", 3720 | "droid2.say_hi()", 3721 | "Robot.how_many()", 3722 | "print('Robots can do some work here.')", 3723 | "print('Robots have finished their work. So lets destroy them.')", 3724 | "droid1.die()", 3725 | "droid2.die()", 3726 | "Robot.how_many()" 3727 | ], 3728 | "description": "class with attribute example" 3729 | }, 3730 | "class=>with_method_1": { 3731 | "prefix": "class=>with_method_1", 3732 | "body": [ 3733 | "class Parrot:", 3734 | "", 3735 | "# instance attributes", 3736 | " def __init__(self, name, age):", 3737 | " self.name = name", 3738 | " self.age = age", 3739 | "", 3740 | "# instance method", 3741 | " def sing(self, song):", 3742 | " return '{} sings {}'.format(self.name, song)", 3743 | "", 3744 | " def dance(self):", 3745 | " return '{} is now dancing'.format(self.name)", 3746 | "", 3747 | "# instantiate the object", 3748 | "blu = Parrot('Blu', 10)", 3749 | "# call our instance methods", 3750 | "print(blu.sing('Happy'))", 3751 | "print(blu.dance())" 3752 | ], 3753 | "description": "class with method example" 3754 | }, 3755 | "class=>with_method_2": { 3756 | "prefix": "class=>with_method_2", 3757 | "body": [ 3758 | "class Person:", 3759 | " def say_hi(self):", 3760 | " print('Hello, how are you?')", 3761 | "p = Person()", 3762 | "p.say_hi()", 3763 | "# The previous 2 lines can also be written as", 3764 | "# Person().say_hi()" 3765 | ], 3766 | "description": "class with method example" 3767 | }, 3768 | "class=>encapsulation": { 3769 | "prefix": "class=>encapsulation", 3770 | "body": [ 3771 | "class Computer:", 3772 | "", 3773 | " def __init__(self):", 3774 | " self.__maxprice = 900", 3775 | "", 3776 | " def sell(self):", 3777 | " print('Selling Price: {}'.format(self.__maxprice))", 3778 | "", 3779 | " def setMaxPrice(self, price):", 3780 | " self.__maxprice = price", 3781 | "", 3782 | "c = Computer()", 3783 | "c.sell()", 3784 | "", 3785 | "# change the price", 3786 | "c.__maxprice = 1000", 3787 | "c.sell()", 3788 | "", 3789 | "# using setter function", 3790 | "c.setMaxPrice(1000)", 3791 | "c.sell()" 3792 | ], 3793 | "description": "class encapsulation example" 3794 | }, 3795 | "class=>polymorphism": { 3796 | "prefix": "class=>polymorphism", 3797 | "body": [ 3798 | "class Parrot:", 3799 | "", 3800 | " def fly(self):", 3801 | " print('Parrot can fly')", 3802 | "", 3803 | " def swim(self):", 3804 | " print('Parrot can not swim')", 3805 | "", 3806 | "class Penguin:", 3807 | "", 3808 | " def fly(self):", 3809 | " print('Penguin can not fly')", 3810 | "", 3811 | " def swim(self):", 3812 | " print('Penguin can swim')", 3813 | "", 3814 | "# common interface", 3815 | "def flying_test(bird):", 3816 | " bird.fly()", 3817 | "", 3818 | "#instantiate objects", 3819 | "blu = Parrot()", 3820 | "peggy = Penguin()", 3821 | "", 3822 | "# passing the object", 3823 | "flying_test(blu)", 3824 | "flying_test(peggy)" 3825 | ], 3826 | "description": "class polymorphism example" 3827 | }, 3828 | "class=>polymorphism": { 3829 | "prefix": "class=>polymorphism", 3830 | "body": [ 3831 | "class Parrot:", 3832 | "", 3833 | " def fly(self):", 3834 | " print('Parrot can fly')", 3835 | "", 3836 | " def swim(self):", 3837 | " print('Parrot can not swim')", 3838 | "", 3839 | "class Penguin:", 3840 | "", 3841 | " def fly(self):", 3842 | " print('Penguin can not fly')", 3843 | "", 3844 | " def swim(self):", 3845 | " print('Penguin can swim')", 3846 | "", 3847 | "# common interface", 3848 | "def flying_test(bird):", 3849 | " bird.fly()", 3850 | "", 3851 | "#instantiate objects", 3852 | "blu = Parrot()", 3853 | "peggy = Penguin()", 3854 | "", 3855 | "# passing the object", 3856 | "flying_test(blu)", 3857 | "flying_test(peggy)" 3858 | ], 3859 | "description": "class polymorphism example" 3860 | } 3861 | } 3862 | --------------------------------------------------------------------------------