├── .env.development ├── .eslintrc-auto-import.json ├── .eslintrc.js ├── .github └── FUNDING.yml ├── .gitignore ├── .npmrc ├── .nvmrc ├── .prettierrc ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── LICENCE ├── README.md ├── contributors ├── contributors.json └── contributors.ts ├── docs ├── blog │ ├── python-comprehensions-step-by-step.md │ ├── python-easy-args-kwargs.md │ ├── python-projects-with-poetry-and-vscode-part-1.md │ ├── python-projects-with-poetry-and-vscode-part-2.md │ ├── python-projects-with-poetry-and-vscode-part-3.md │ └── python-sets-what-why-how.md ├── builtin │ ├── abs.md │ ├── aiter.md │ ├── all.md │ ├── any.md │ ├── ascii.md │ ├── bin.md │ ├── bool.md │ ├── breakpoint.md │ ├── bytearray.md │ ├── bytes.md │ ├── callable.md │ ├── chr.md │ ├── classmethod.md │ ├── compile.md │ ├── complex.md │ ├── delattr.md │ ├── dict.md │ ├── dir.md │ ├── divmod.md │ ├── enumerate.md │ ├── eval.md │ ├── exec.md │ ├── filter.md │ ├── float.md │ ├── format.md │ ├── frozenset.md │ ├── getattr.md │ ├── globals.md │ ├── hasattr.md │ ├── hash.md │ ├── help.md │ ├── hex.md │ ├── id.md │ ├── import.md │ ├── input.md │ ├── int.md │ ├── isinstance.md │ ├── issubclass.md │ ├── iter.md │ ├── len.md │ ├── list.md │ ├── locals.md │ ├── map.md │ ├── max.md │ ├── memoryview.md │ ├── min.md │ ├── next.md │ ├── object.md │ ├── oct.md │ ├── open.md │ ├── ord.md │ ├── pow.md │ ├── print.md │ ├── property.md │ ├── range.md │ ├── repr.md │ ├── reversed.md │ ├── round.md │ ├── set.md │ ├── setattr.md │ ├── slice.md │ ├── sorted.md │ ├── staticmethod.md │ ├── str.md │ ├── sum.md │ ├── super.md │ ├── tuple.md │ ├── type.md │ ├── vars.md │ └── zip.md ├── cheatsheet │ ├── args-and-kwargs.md │ ├── basics.md │ ├── built-in-functions.md │ ├── comprehensions.md │ ├── context-manager.md │ ├── control-flow.md │ ├── dataclasses.md │ ├── debugging.md │ ├── decorators.md │ ├── dictionaries.md │ ├── exception-handling.md │ ├── file-directory-path.md │ ├── functions.md │ ├── json-yaml.md │ ├── lists-and-tuples.md │ ├── main.md │ ├── manipulating-strings.md │ ├── oop-basics.md │ ├── reading-and-writing-files.md │ ├── regular-expressions.md │ ├── sets.md │ ├── setup-py.md │ ├── string-formatting.md │ └── virtual-environments.md └── modules │ ├── copy-module.md │ ├── datetime-module.md │ ├── itertools-module.md │ ├── json-module.md │ ├── os-module.md │ ├── pathlib-module.md │ ├── random-module.md │ ├── shelve-module.md │ └── zipfile-module.md ├── index.html ├── netlify.toml ├── package.json ├── pnpm-lock.yaml ├── postcss.config.js ├── public ├── _headers ├── _redirects ├── android-chrome-192x192.png ├── android-chrome-384x384.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── browserconfig.xml ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── favicon.svg ├── fonts │ ├── Inter-italic.var.woff2 │ ├── Inter-roman.var.woff2 │ ├── lexend.txt │ └── lexend.woff2 ├── googleccbf6035fc9d727f.html ├── icons │ └── favicon.svg ├── logo-light.svg ├── logo.svg ├── mstile-144x144.png ├── mstile-150x150.png ├── mstile-310x150.png ├── mstile-310x310.png ├── mstile-70x70.png ├── netlify.svg ├── pylogo.png ├── robots.txt ├── safari-pinned-tab.svg ├── screenshots │ ├── dark.png │ ├── frame_dark.png │ ├── frame_generic_dark.png │ ├── frame_generic_light.png │ ├── frame_light.png │ └── light.png ├── site.webmanifest ├── snake.svg ├── social │ └── social_banner.png ├── sponsor.mp4 ├── sponsors │ ├── kinsta │ │ ├── SVG │ │ │ ├── PythonCheatSheet_banner_Text.svg │ │ │ ├── PythonCheatSheet_banner_button-main.svg │ │ │ ├── PythonCheatSheet_banner_kinsta_logo.svg │ │ │ └── kinsta-mobile.png │ │ ├── kinsta-logo-alpha-purple.png │ │ ├── kinsta-logo-alpha-white.png │ │ ├── kinsta-logo1.png │ │ ├── kinsta-logo2.png │ │ └── kinsta-logo3.png │ └── practity │ │ └── practity.webp └── user-avatars │ ├── Acumane.png │ ├── AdamRosas27.png │ ├── Arham-Fox.png │ ├── BenIsenstein.png │ ├── CodeWithBishal.png │ ├── DevGauravJoshi.png │ ├── Gaura.png │ ├── HasnatHridoy.png │ ├── ImgBotApp.png │ ├── LairdStreak.png │ ├── MaT1g3R.png │ ├── Matthew-Nicholson.png │ ├── MozarM.png │ ├── PmS-crypto.png │ ├── QuarkZ26.png │ ├── RichardScottOZ.png │ ├── SeaSide53.png │ ├── Sonatrix.png │ ├── Vishesh-dd4723.png │ ├── Yaya9256.png │ ├── abdussalam02.png │ ├── adeelmc.png │ ├── aloklal99.png │ ├── alvyynm.png │ ├── asenov.png │ ├── azanbinzahid.png │ ├── ckartchner.png │ ├── classic-arnold.png │ ├── comrade5.png │ ├── connected-tcaceres.png │ ├── damiankrolik.png │ ├── danielpclin.png │ ├── darkpixlz.png │ ├── decodingchris.png │ ├── ehmsu.png │ ├── evanrrees.png │ ├── fPkX6F1nGTX.png │ ├── firdousmurtaza1.png │ ├── flymemoryRPA.png │ ├── gaurav-jo1.png │ ├── gsemet.png │ ├── gspagare.png │ ├── gulu42.png │ ├── hacktron95.png │ ├── johntheholman.png │ ├── kakasahebKK.png │ ├── kavin5kumar.png │ ├── lukaszwojcik89.png │ ├── madeelchaudhary.png │ ├── matteodem.png │ ├── michaelbaluja.png │ ├── mohammedalrawi98.png │ ├── msohaib9.png │ ├── mu-us61.png │ ├── noraa-july-stoke.png │ ├── nugel.png │ ├── omerts.png │ ├── omii2k01.png │ ├── paulwongx.png │ ├── pranayat.png │ ├── prashanthbhat203.png │ ├── pyxfluff.png │ ├── qkniep.png │ ├── qudongfang.png │ ├── rawatdev.png │ ├── rbuzzell.png │ ├── richjohnsonxyz.png │ ├── roopeshvs.png │ ├── sage-gendron.png │ ├── samithamphk.png │ ├── senlog.png │ ├── shirinapr.png │ ├── skyunna.png │ ├── supersandra.png │ ├── szTheory.png │ ├── techboy-coder.png │ ├── thacer13.png │ ├── thoughtworks-tcaceres.png │ ├── tomfun.png │ ├── unixorn.png │ ├── vaibhavb02.png │ ├── wilfredinni.png │ ├── wn9237.png │ ├── xcsnowcity.png │ └── zdouble.png ├── renovate.json ├── scripts ├── fetch-avatars.ts └── fetch-contributors.ts ├── src ├── App.vue ├── assets │ └── logo.png ├── auto-imports.d.ts ├── components.d.ts ├── components │ ├── AlgoliaDocSearch.vue │ ├── BlogTitleHeader.vue │ ├── CarbonAds.vue │ ├── Contributors.vue │ ├── EmptySection.vue │ ├── KinstaBanner.vue │ ├── NetlifyBadge.vue │ ├── Prose.vue │ ├── SubscriptionForm.vue │ ├── icons │ │ ├── ArrowIcon.vue │ │ ├── BugIcon.vue │ │ ├── EditIcon.vue │ │ ├── GithubIcon.vue │ │ ├── GridIcon.vue │ │ ├── LightBulbIcon.vue │ │ ├── PluginIcon.vue │ │ ├── QuestionIcon.vue │ │ ├── ReferenceIcon.vue │ │ └── WarningIcon.vue │ ├── layout │ │ ├── TheFooter.vue │ │ ├── TheNavbar.vue │ │ ├── TheNavbarReader.vue │ │ ├── TheSidebarDesktop.vue │ │ ├── TheSidebarMobile.vue │ │ ├── TheSidebarNavigation.vue │ │ └── TheToc.vue │ ├── sponsors │ │ ├── VpsServer.vue │ │ ├── kinsta.vue │ │ └── practity.vue │ └── ui │ │ ├── BaseBadge.vue │ │ ├── BaseBadgeNotice.vue │ │ ├── BaseBadgeSecondary.vue │ │ ├── BaseBanner.vue │ │ ├── BaseCustomizableLinkCard.vue │ │ ├── BaseLinkCard.vue │ │ ├── BasePagination.vue │ │ ├── BaseReaderMode.vue │ │ ├── BaseThemeToggle.vue │ │ ├── BaseTitle.vue │ │ ├── disclaimer │ │ ├── BaseDisclaimer.vue │ │ ├── BaseDisclaimerContent.vue │ │ └── BaseDisclaimerTitle.vue │ │ ├── newBadge.vue │ │ ├── table │ │ ├── BaseTable.vue │ │ ├── BaseTableItem.vue │ │ └── BaseTableRow.vue │ │ └── warning │ │ ├── BaseWarning.vue │ │ ├── BaseWarningContent.vue │ │ └── BaseWarningTitle.vue ├── composables │ ├── carbon.ts │ ├── dark.ts │ ├── meta.ts │ ├── scroll.ts │ └── toc.ts ├── env.d.ts ├── layouts │ ├── article.vue │ ├── blog.vue │ ├── default.vue │ ├── empty.vue │ ├── fullPage.vue │ └── fullWidth.vue ├── main.ts ├── modules │ ├── analytics.ts │ ├── pinia.ts │ └── pwa.ts ├── pages │ ├── [...all].vue │ ├── blog │ │ └── index.vue │ ├── changelog.md │ ├── contributing.md │ ├── index.vue │ ├── newsletter.vue │ └── sponsor.vue ├── store │ ├── navigation.ts │ ├── newsletter.ts │ └── reader.ts ├── styles │ ├── carbon.css │ ├── docsearch.css │ ├── fonts.css │ ├── index.css │ └── markdown.css ├── types.ts └── types │ ├── index.d.ts │ └── ui.ts ├── tailwind.config.js ├── tests └── basic.test.ts ├── tsconfig.json ├── tsconfig.node.json └── vite.config.ts /.env.development: -------------------------------------------------------------------------------- 1 | VITE_IN_PRODUCTION=false 2 | VITE_BASE_URL=next.pythoncheatsheet.org 3 | VITE_GTAG=G-RETM00X0HZ 4 | 5 | VITE_DOCSEARCH_CONTAINER=#docsearch 6 | VITE_DOCSEARCH_APP_ID=5Y2U5SSBPV 7 | VITE_DOCSEARCH_INDEX_NAME=pythoncheatsheet 8 | VITE_DOCSEARCH_API_KEY=feeb2b112b0775e792655f85233b3979 9 | 10 | VITE_LOAD_CARBON=true 11 | VITE_CARBON_SERVE=CVAIKKQM 12 | VITE_CARBON_PLACEMENT=carbonadsnet 13 | 14 | VITE_NEWSLETTER=true 15 | VITE_GRUDGET_ENDPOINT=https://api.grudget.com 16 | VITE_GRUDGET_NEWSLETTER=xxxxxxxxxxxxx 17 | VITE_GRUDGET_TOKEN=xxxxxxxxxxx -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | node: true, 4 | }, 5 | extends: [ 6 | 'eslint:recommended', 7 | 'plugin:vue/vue3-recommended', 8 | 'prettier', 9 | './.eslintrc-auto-import.json', 10 | ], 11 | rules: { 12 | // override/add rules settings here, such as: 13 | 'vue/no-unused-vars': 'off', 14 | 'vue/multi-word-component-names': 'off', 15 | 'Parsing error: Unexpected token as': 'off', 16 | // 'no-unused-vars': 'off', 17 | }, 18 | parserOptions: { 19 | ecmaVersion: 12, 20 | sourceType: 'module', 21 | parser: '@typescript-eslint/parser', 22 | }, 23 | } 24 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: wilfredinni 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .idea 17 | .DS_Store 18 | *.suo 19 | *.ntvs* 20 | *.njsproj 21 | *.sln 22 | *.sw? 23 | .vite-ssg-temp 24 | coverage 25 | .env 26 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | shamefully-hoist=true 2 | strict-peer-dependencies=false -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "useTabs": false, 4 | "endOfLine": "auto", 5 | "singleQuote": true, 6 | "bracketSpacing": true, 7 | "arrowParens": "always" 8 | } -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 wilfredinni 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 | -------------------------------------------------------------------------------- /contributors/contributors.json: -------------------------------------------------------------------------------- 1 | [ 2 | "wilfredinni", 3 | "Sonatrix", 4 | "MaT1g3R", 5 | "samithamphk", 6 | "rawatdev", 7 | "gsemet", 8 | "vaibhavb02", 9 | "LairdStreak", 10 | "Acumane", 11 | "szTheory", 12 | "flymemoryRPA", 13 | "fPkX6F1nGTX", 14 | "gspagare", 15 | "skyunna", 16 | "ckartchner", 17 | "matteodem", 18 | "noraa-july-stoke", 19 | "lukaszwojcik89", 20 | "omii2k01", 21 | "danielpclin", 22 | "nugel", 23 | "michaelbaluja", 24 | "rbuzzell", 25 | "PmS-crypto", 26 | "MozarM", 27 | "johntheholman", 28 | "HasnatHridoy", 29 | "azanbinzahid", 30 | "abdussalam02", 31 | "Yaya9256", 32 | "Vishesh-dd4723", 33 | "thoughtworks-tcaceres", 34 | "techboy-coder", 35 | "shirinapr", 36 | "senlog", 37 | "SeaSide53", 38 | "supersandra", 39 | "sage-gendron", 40 | "roopeshvs", 41 | "RichardScottOZ", 42 | "richjohnsonxyz", 43 | "AdamRosas27", 44 | "alvyynm", 45 | "comrade5", 46 | "damiankrolik", 47 | "ehmsu", 48 | "firdousmurtaza1", 49 | "kakasahebKK", 50 | "msohaib9", 51 | "omerts", 52 | "paulwongx", 53 | "qudongfang", 54 | "thacer13", 55 | "xcsnowcity", 56 | "zdouble", 57 | "aloklal99", 58 | "Arham-Fox", 59 | "classic-arnold", 60 | "BenIsenstein", 61 | "CodeWithBishal", 62 | "decodingchris", 63 | "evanrrees", 64 | "Gaura", 65 | "gaurav-jo1", 66 | "tomfun", 67 | "ImgBotApp", 68 | "unixorn", 69 | "kavin5kumar", 70 | "asenov", 71 | "Matthew-Nicholson", 72 | "mohammedalrawi98", 73 | "adeelmc", 74 | "mu-us61", 75 | "wn9237", 76 | "hacktron95", 77 | "pyxfluff", 78 | "pranayat", 79 | "prashanthbhat203", 80 | "QuarkZ26", 81 | "qkniep" 82 | ] -------------------------------------------------------------------------------- /contributors/contributors.ts: -------------------------------------------------------------------------------- 1 | import contributorNames from './contributors.json' 2 | 3 | export interface Contributor { 4 | name: string 5 | avatar: string 6 | repository: string 7 | } 8 | 9 | const contributorsAvatars: Record = {} 10 | 11 | const getAvatarUrl = (name: string) => 12 | import.meta.hot 13 | ? `https://github.com/${name}.png` 14 | : `/user-avatars/${name}.png` 15 | 16 | export const contributors = (contributorNames as string[]).reduce( 17 | (acc, name) => { 18 | contributorsAvatars[name] = getAvatarUrl(name) 19 | acc.push({ 20 | name, 21 | avatar: contributorsAvatars[name], 22 | repository: `https://github.com/${name}`, 23 | }) 24 | return acc 25 | }, 26 | [] as Contributor[] 27 | ) 28 | -------------------------------------------------------------------------------- /docs/builtin/abs.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python abs() built-in function - Python Cheatsheet 3 | description: Return the absolute value of a number. The argument may be an integer, a floating point number, or an object implementing __abs__(). If the argument is a complex number, its magnitude is returned. 4 | --- 5 | 6 | 7 | Python abs() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the absolute value of a number. The argument may be an integer, a floating point number, or an object implementing __abs__(). If the argument is a complex number, its magnitude is returned. 16 | 17 | 18 | 19 | ```python 20 | >>> abs(-1) 21 | # 1 22 | >>> abs(0) 23 | # 0 24 | >>> abs(1) 25 | # 1 26 | >>> abs(3.14) 27 | # 3.14 28 | >>> abs(3 + 2j) 29 | # 3.6055512754639896 30 | >>> abs(0x10) 31 | # 16 32 | >>> abs(0b10) 33 | # 2 34 | >>> abs(0o20) 35 | # 16 36 | ``` 37 | -------------------------------------------------------------------------------- /docs/builtin/aiter.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python aiter() built-in function - Python Cheatsheet 3 | description: Return an asynchronous iterator for an asynchronous iterable. Equivalent to calling x.__aiter__(). 4 | --- 5 | 6 | 7 | Python aiter() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return an asynchronous iterator for an asynchronous iterable. Equivalent to calling x.__aiter__(). aiter() is an async equivalent of iter() 16 | 17 | 18 | 19 | ## Example 20 | 21 | ```python 22 | >>> async def aitersync(iterable): 23 | ... results = [] 24 | ... async for x in aiter(iterable): 25 | ... results.append(x) 26 | ... return iter(results) 27 | ``` 28 | -------------------------------------------------------------------------------- /docs/builtin/all.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python all() built-in function - Python Cheatsheet 3 | description: Return True if all elements of the iterable are true (or if the iterable is empty). 4 | --- 5 | 6 | 7 | Python all() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return True if all elements of the iterable are true (or if the iterable is empty). 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> all([True, True, True]) 23 | # True 24 | 25 | >>> all((0, True, False)) 26 | # False 27 | 28 | >>> all({1, 1, 1}) 29 | # True 30 | ``` 31 | -------------------------------------------------------------------------------- /docs/builtin/any.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python any() built-in function - Python Cheatsheet 3 | description: Return True if any element of the iterable is true. If the iterable is empty, return False. 4 | --- 5 | 6 | 7 | Python any() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return True if any element of the iterable is true. If the iterable is empty, return False. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> any([False, False, False]) 23 | # False 24 | 25 | >>> any((0, True, False)) 26 | # True 27 | 28 | >>> any({0, 0, 0}) 29 | # False 30 | ``` 31 | -------------------------------------------------------------------------------- /docs/builtin/ascii.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python ascii() built-in function - Python Cheatsheet 3 | description: As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \x, \u, or \U escapes. 4 | --- 5 | 6 | 7 | Python ascii() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | As repr(), return a string containing a printable representation of an object, but escape the non-ASCII characters in the string returned by repr() using \x, \u, or \U escapes. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> ascii('A') 23 | # 'A' 24 | 25 | >>> ascii('ë') 26 | # '\xeb' 27 | 28 | >>> ascii(['A', 'ë']) 29 | # ['A', '\xeb'] 30 | ``` 31 | -------------------------------------------------------------------------------- /docs/builtin/bin.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python bin() built-in function - Python Cheatsheet 3 | description: Convert an integer number to a binary string prefixed with “0b”. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer. 4 | --- 5 | 6 | 7 | Python bin() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Convert an integer number to a binary string prefixed with “0b”. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> bin(1) 23 | # '0b1' 24 | 25 | >>> bin(10) 26 | # '0b1010' 27 | 28 | >>> bin(100) 29 | # '0b1100100' 30 | 31 | >>> bin(1000) 32 | # '0b1111101000' 33 | ``` 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /docs/builtin/bool.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python bool() built-in function - Python Cheatsheet 3 | description: Return a Boolean value, i.e. one of True or False. x is converted using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise, it returns True. The bool class is a subclass of int. It cannot be subclassed further. Its only instances are False and True. 4 | --- 5 | 6 | 7 | Python bool() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a Boolean value, True or False. x is converted using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise, it returns True. The bool class is a subclass of int. It cannot be subclassed further. Its only instances are False and True. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> bool(0) 23 | # False 24 | 25 | >>> bool(1) 26 | # True 27 | 28 | >>> bool(2) 29 | # True 30 | 31 | >>> bool('3') 32 | # True 33 | 34 | >>> bool(False) 35 | # False 36 | 37 | >>> bool(True) 38 | # True 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/builtin/breakpoint.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python breakpoint() built-in function - Python Cheatsheet 3 | description: This function drops you into the debugger at the call site. Specifically, it calls sys.breakpointhook(), passing args and kws straight through. By default, sys.breakpointhook() calls pdb.set_trace() expecting no arguments. In this case, it is purely a convenience function so you don’t have to explicitly import pdb or type as much code to enter the debugger. However, sys.breakpointhook() can be set to some other function and breakpoint() will automatically call that, allowing you to drop into the debugger of choice. 4 | --- 5 | 6 | 7 | Python breakpoint() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | This function drops you into the debugger at the call site [...]. 16 |
17 | Python breakpoint() calls Python debugger at a given line 18 |
19 |
20 | 21 | ## Example 22 | 23 | ```python 24 | >>> # Create a loop over 5 integers 25 | >>> for i in range(5): 26 | ... # Stream i to stdout 27 | ... print(i) 28 | ... # Create breakpoint at # 3 29 | ... if i == 3: 30 | ... breakpoint() 31 | ... 32 | # 0 33 | # 1 34 | # 2 35 | # 3 36 | # > c:\users\user\path\to\your\project\example.py(24)() 37 | # -> for i in range(5): 38 | # (Pdb) 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/builtin/bytearray.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python bytearray() built-in function - Python Cheatsheet 3 | description: Return a new array of bytes. The bytearray class is a mutable sequence of integers in the range [...]. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the bytes type has [...] 4 | --- 5 | 6 | 7 | Python bytearray() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a new array of bytes. The bytearray class is a mutable sequence of integers in the range [...]. It has most of the usual methods of mutable sequences, described in Mutable Sequence Types, as well as most methods that the bytes type has [...]. 16 | 17 | 18 | 19 | ## Introduction 20 | 21 | A `bytearray` object in Python is similar to a list of integers, but instead of storing numbers, it stores bytes. These bytes can represent binary data, such as an image or a file, or they can represent ASCII or UTF-8 encoded text. 22 | 23 | A `bytearray` object is mutable, meaning its elements can be changed after it is created. It also has a variety of built-in methods that allow you to manipulate the bytes, such as `append()`, `extend()`, `insert()`, and `remove()`. 24 | 25 | You can create a `bytearray` object in several ways. One way is to use the `bytearray()` constructor and pass it a string, a bytes object, or a `bytearray` object. For example: 26 | 27 | ```python 28 | >>> data = "Hello, World!" 29 | >>> bytearray_obj = bytearray(data, "utf-8") 30 | >>> print(bytearray_obj) 31 | # bytearray(b'Hello, World!') 32 | ``` 33 | 34 | Another way is to use the bytes() function and then convert it to a bytearray object using the bytearray() function: 35 | 36 | ```python 37 | >>> data = b"Hello, World!" 38 | >>> bytearray_obj = bytearray(data) 39 | >>> print(bytearray_obj) 40 | # bytearray(b'Hello, World!') 41 | ``` 42 | 43 | Bytearray objects are useful in situations where you need to manipulate binary data or when you want to efficiently modify large amounts of data. -------------------------------------------------------------------------------- /docs/builtin/bytes.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python bytes() built-in function - Python Cheatsheet 3 | description: Return a new “bytes” object which is an immutable sequence of integers in the range [...]. bytes is an immutable version of bytearray – it has the same non-mutating methods and the same indexing and slicing behavior. 4 | --- 5 | 6 | 7 | Python bytes() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a new “bytes” object which is an immutable sequence of integers in the range [...]. bytes is an immutable version of bytearray – it has the same non-mutating methods and the same indexing and slicing behavior. 16 | 17 | 18 | 19 | ## Introduction 20 | 21 | In Python, the `bytes` type is an immutable sequence of single bytes. It represents a sequence of integers in the range of 0 to 255, which can be used to represent binary data such as images, audio, or other types of files. 22 | 23 | You can create a bytes object in several ways. One way is to use the `bytes()` constructor and pass it a string, a bytearray object, or a bytes object. For example: 24 | 25 | ```python 26 | >>> data = "Hello, World!" 27 | >>> bytes_obj = bytes(data, "utf-8") 28 | >>> print(bytes_obj) 29 | # b'Hello, World!' 30 | ``` 31 | 32 | Another way is to use a literal notation prefixing the string with `b` or `B`: 33 | 34 | ```python 35 | data = b"Hello, World!" 36 | print(data) 37 | # b'Hello, World!' 38 | ``` 39 | 40 | You can also use slicing and indexing to access individual bytes, and use built-in methods such as `count()` and `find()` to search for specific bytes within the object. 41 | 42 | The `bytes` type is useful when you need to work with binary data that should not be modified, such as the contents of a file. Since it is immutable, it can be used in situations where the data needs to be protected from accidental modification. -------------------------------------------------------------------------------- /docs/builtin/chr.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python chr() built-in function - Python Cheatsheet 3 | description: Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returns the string 'a', while chr(8364) returns the string '€'. This is the inverse of ord(). 4 | --- 5 | 6 | 7 | Python chr() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returns the string 'a', while chr(8364) returns the string '€'. This is the inverse of ord(). 16 | 17 | 18 | 19 | ## Introduction 20 | 21 | The `chr()` function in Python is a built-in function that takes an integer as an argument and returns a string representing the corresponding Unicode character. 22 | 23 | The integer passed to the `chr()` function should be in the range of 0 to 65535, which corresponds to the range of valid Unicode characters. 24 | 25 | ```python 26 | >>> print(chr(97)) 27 | # 'a' 28 | >>> print(chr(65)) 29 | # 'A' 30 | >>> print(chr(120)) 31 | # 'x' 32 | ``` 33 | 34 | The `chr()` function is the inverse of the `ord()` function, which takes a single character as an argument and returns the corresponding integer. 35 | 36 | ```python 37 | print(ord('a')) 38 | # 97 39 | print(ord('A')) 40 | # 65 41 | print(ord('x')) 42 | # 120 43 | ``` 44 | 45 | The `chr()` function can be useful when working with text and character data, particularly when working with Unicode characters. For example, you can use it to convert an integer representing a Unicode code point to the corresponding character, or to generate a string of characters from a range of integers. -------------------------------------------------------------------------------- /docs/builtin/classmethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python classmethod() built-in function - Python Cheatsheet 3 | description: Transform a method into a class method. A class method receives the class as an implicit first argument, just like an instance method receives the instance. 4 | --- 5 | 6 | 7 | Python classmethod() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Transform a method into a class method. A class method receives the class as an implicit first argument, just like an instance method receives the instance. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | class Counter: 23 | def __init__(self): 24 | self.count = 0 25 | 26 | def increment(self): 27 | self.count += 1 28 | return self.count 29 | 30 | @classmethod # passes the class as the first argument to the method instead of passing the instance 31 | def get_new_instance(cls): 32 | return cls() 33 | 34 | if __name__ == "__main__": 35 | counter = Counter() 36 | print(counter.increment()) 37 | # 1 38 | 39 | counter = counter.get_new_instance() 40 | print(counter.increment()) 41 | # 1 42 | ``` 43 | -------------------------------------------------------------------------------- /docs/builtin/compile.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python compile() built-in function - Python Cheatsheet 3 | description: Compile the source into a code or AST object. Code objects can be executed by exec() or eval(). source can either be a normal string, a byte string, or an AST object. Refer to the ast module documentation for information on how to work with AST objects. 4 | --- 5 | 6 | 7 | Python compile() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Compile the source into a code or AST object. Code objects can be executed by exec() or eval(). source can either be a normal string, a byte string, or an AST object. Refer to the ast module documentation for information on how to work with AST objects. 16 | 17 | 18 | 19 | ## Introduction 20 | 21 | The `compile()` function in Python is a built-in function that is used to convert a string or an Abstract Syntax Tree (AST) object into a code object. This code object can then be executed by functions like `exec()` or `eval()`. 22 | 23 | ## Example 24 | 25 | Here's a basic example of how it works: 26 | 27 | ```python 28 | code_string = """ 29 | def hello_world(): 30 | print('Hello, world!') 31 | """ 32 | 33 | # Compile the string into a code object 34 | code_object = compile(code_string, '', 'exec') 35 | 36 | # Execute the code object 37 | exec(code_object) 38 | 39 | # Call the function defined in the code object 40 | hello_world() 41 | ``` 42 | 43 | In this example, a string containing Python code is compiled into a code object using `compile()`, and then executed with `exec()`. The function `hello_world()` defined in the string is then available to be called. -------------------------------------------------------------------------------- /docs/builtin/complex.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python complex() built-in function - Python Cheatsheet 3 | description: Return a complex number with the value real + imag*1j or convert a string or number to a complex number. [...] Each argument may be any numeric type (including complex). If imag is omitted, it defaults to zero and the constructor serves as a numeric conversion like int and float. If both arguments are omitted, returns 0j. 4 | --- 5 | 6 | 7 | Python complex() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a complex number with the value real + imag*1j or convert a string or number to a complex number. [...] Each argument may be any numeric type (including complex). If imag is omitted, it defaults to zero and the constructor serves as a numeric conversion like int and float. If both arguments are omitted, returns 0j. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> complex(1) 23 | # (1+0j) 24 | >>> complex('1') 25 | # (1+0j) 26 | >>> complex(100) 27 | # (100+0j) 28 | >>> complex('100') 29 | # (100+0j) 30 | ``` 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /docs/builtin/delattr.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python delattr() built-in function - Python Cheatsheet 3 | description: This is a relative of setattr(). The arguments are an object and a string. The string must be the name of one of the object’s attributes. The function deletes the named attribute, provided the object allows it. For example, delattr(x, 'foobar') is equivalent to del x.foobar. 4 | --- 5 | 6 | 7 | Python delattr() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | This is a relative of setattr(). The arguments are an object and a string. The string must be the name of one of the object’s attributes. The function deletes the named attribute, provided the object allows it. For example, delattr(x, 'foobar') is equivalent to del x.foobar. 16 | 17 | 18 | 19 | ```python 20 | class Person: 21 | def __init__(self, name, age): 22 | self.name = name 23 | self.age = age 24 | 25 | >>> person = Person("John", 30) 26 | >>> delattr(person, 'age') 27 | >>> person.__dict__ 28 | # {'name': 'John'} 29 | 30 | class Car: 31 | def __init__(self, make, model): 32 | self.make = make 33 | self.model = model 34 | 35 | >>> car = Car("Toyota", "Corolla") 36 | >>> try: 37 | ... delattr(car, 'year') 38 | ... except AttributeError as e: 39 | ... print(f"Error: {e}") 40 | # Error: 'Car' object has no attribute 'year' 41 | ``` 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /docs/builtin/dict.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python dict() built-in function - Python Cheatsheet 3 | description: Create a new dictionary. The dict object is the dictionary class. See dict and Mapping Types — dict for documentation about this class. 4 | --- 5 | 6 | 7 | Python dict() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Create a new dictionary. The dict object is the dictionary class. See dict and Mapping Types — dict for documentation about this class. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> a = dict() 23 | >>> type(a) 24 | # 25 | ``` 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /docs/builtin/divmod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python divmod() built-in function - Python Cheatsheet 3 | description: Take two (non-complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using integer division. With mixed operand types, the rules for binary arithmetic operators apply. 4 | --- 5 | 6 | 7 | Python divmod() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Take two (non-complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using integer division. With mixed operand types, the rules for binary arithmetic operators apply. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> divmod(2, 2) 23 | # (1, 0) 24 | >>> divmod(10, 2) 25 | # (5, 0) 26 | >>> divmod(7, 2) 27 | # (3, 1) 28 | ``` 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /docs/builtin/enumerate.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python enumerate() built-in function - Python Cheatsheet 3 | description: Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. The __next__() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterable. 4 | --- 5 | 6 | 7 | Python enumerate() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return an enumerate object. iterable must be a sequence, an iterator, or some other object which supports iteration. The __next__() method of the iterator returned by enumerate() returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over iterable. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> l = enumerate([1, 2, 3, 4, 5]) 23 | >>> l 24 | # 25 | >>> l.__next__() 26 | # (0, 1) 27 | >>> l.__next__() 28 | # (1, 2) 29 | >>> l.__next__() 30 | # (2, 3) 31 | >>> l.__next__() 32 | # (3, 4) 33 | >>> l.__next__() 34 | # (4, 5) 35 | >>> l.__next__() 36 | # Traceback (most recent call last): 37 | # File "", line 1, in 38 | # StopIteration 39 | ``` 40 | 41 | `enumerate` is usually used in a `for` loop to get the index of an item: 42 | 43 | ```python 44 | >>> for i, item in enumerate([1, 2, 3, 4, 5]): 45 | ... print(f"Index: {i}, Item: {item}") 46 | ... 47 | # Index: 0, Item: 1 48 | # Index: 1, Item: 2 49 | # Index: 2, Item: 3 50 | # Index: 3, Item: 4 51 | # Index: 4, Item: 5 52 | ``` 53 | -------------------------------------------------------------------------------- /docs/builtin/eval.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python eval() built-in function - Python Cheatsheet 3 | description: The arguments are a string and optional globals and locals. If provided, globals must be a dictionary. If provided, locals can be any mapping object. 4 | --- 5 | 6 | 7 | Python eval() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | The arguments are a string and optional globals and locals. If provided, globals must be a dictionary. If provided, locals can be any mapping object. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> eval('1 + 4') 23 | # 5 24 | 25 | >>> eval('print("Hello World!")') 26 | # Hello World! 27 | 28 | >>> x = 10 29 | >>> eval('x == 10') 30 | # True 31 | ``` 32 | -------------------------------------------------------------------------------- /docs/builtin/filter.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python filter() built-in function - Python Cheatsheet 3 | description: Construct an iterator from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed. 4 | --- 5 | 6 | 7 | Python filter() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Construct an iterator from those elements of iterable for which function returns true. iterable may be either a sequence, a container which supports iteration, or an iterator. If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed. 16 | 17 | 18 | 19 | ## Introduction 20 | 21 | The `filter` method in Python is a built-in function that allows you to `filter` a sequence (e.g., a list, a tuple, etc.) by applying a certain condition to each element in the sequence. The filter method returns a new sequence containing only the elements that meet the specified condition. 22 | 23 | Here is a simple example of using the filter method to filter a list of numbers and keep only the even numbers: 24 | 25 | ## Example 26 | 27 | ```python 28 | >>> def is_even(num): 29 | ... return num % 2 == 0 30 | ... 31 | >>> numbers = [1, 2, 3, 4, 5, 6] 32 | >>> even_numbers = list(filter(is_even, numbers)) 33 | >>> print(even_numbers) 34 | >>> [2, 4, 6] 35 | ``` 36 | 37 | In this example, the `is_even` function is defined to determine whether a number is even or not. The filter method takes `two arguments`: the `first argument` is the function to apply to each element of the list, and the `second argument` is the list to be filtered. The filter method returns an iterable, which is then converted to a list and stored in the even_numbers variable. The final output is the list of even numbers from the original list. 38 | -------------------------------------------------------------------------------- /docs/builtin/float.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python float() built-in function - Python Cheatsheet 3 | description: Return a floating point number constructed from a number or string x. 4 | --- 5 | 6 | 7 | Python float() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a floating point number constructed from a number or string x. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> float('10') 23 | # 10.0 24 | >>> float(10) 25 | # 10.0 26 | ``` 27 | -------------------------------------------------------------------------------- /docs/builtin/format.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python format() built-in function - Python Cheatsheet 3 | description: Convert a value to a “formatted” representation, as controlled by format_spec. The interpretation of format_spec will depend on the type of the value argument. [...]. 4 | --- 5 | 6 | 7 | Python format() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Convert a value to a “formatted” representation, as controlled by format_spec. The interpretation of format_spec will depend on the type of the value argument. [...]. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | name = 'Micheal' 23 | company = 'Dunder Mifflin' 24 | 25 | print("My name is {0} and I work for {1}.".format(name, company)) 26 | 27 | # Formatting string (faster and easier) 28 | print(f"My name is {name} and I work for {company}.") 29 | ``` 30 | -------------------------------------------------------------------------------- /docs/builtin/frozenset.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python frozenset() built-in function - Python Cheatsheet 3 | description: Return a new frozenset object, optionally with elements taken from iterable. frozenset is a built-in class. See frozenset and Set Types — set, frozenset for documentation about this class. 4 | --- 5 | 6 | 7 | Python frozenset() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a new frozenset object, optionally with elements taken from iterable. frozenset is a built-in class. See frozenset and Set Types — set, frozenset for documentation about this class. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> frozenset([1, 2, 3]) 23 | # frozenset({1, 2, 3}) 24 | 25 | >>> frozenset({1, 2, 3}) 26 | # frozenset({1, 2, 3}) 27 | 28 | >>> frozenset((1, 2, 3)) 29 | # frozenset({1, 2, 3}) 30 | ``` 31 | -------------------------------------------------------------------------------- /docs/builtin/getattr.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python getattr() built-in function - Python Cheatsheet 3 | description: Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. 4 | --- 5 | 6 | 7 | Python getattr() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. 16 | 17 | 18 | 19 | ## Syntax 20 | 21 | ```python 22 | getattr(object, name) 23 | ``` 24 | or 25 | ```python 26 | getattr(object, name, default) 27 | ``` 28 | -`object`: The object whose attribute you want to access. 29 | 30 | -`name`: The name of the attribute you want to retrieve. 31 | 32 | -`default`: (Optional) The value to be returned if the attribute is not found. If not provided, `None` is returned. 33 | 34 | ## Example 35 | 36 | ```python 37 | class Example: 38 | attribute = "Hello, World!" 39 | 40 | # Creating an instance of the class 41 | obj = Example() 42 | 43 | # Using getattr to access the attribute 44 | value = getattr(obj, 'attribute', 'Nothing found') 45 | 46 | print(value) # Output: Hello, World! 47 | 48 | # If the 'attribute' does not exist then 'Nothing found' will be printed. 49 | ``` 50 | 51 | 52 | -------------------------------------------------------------------------------- /docs/builtin/globals.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python globals() built-in function - Python Cheatsheet 3 | description: Return the dictionary implementing the current module namespace. For code within functions, this is set when the function is defined and remains the same regardless of where the function is called. 4 | --- 5 | 6 | 7 | Python globals() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the dictionary implementing the current module namespace. For code within functions, this is set when the function is defined and remains the same regardless of where the function is called. 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/builtin/hasattr.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python hasattr() built-in function - Python Cheatsheet 3 | description: The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.) 4 | --- 5 | 6 | 7 | Python hasattr() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.) 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/builtin/hash.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python hash() built-in function - Python Cheatsheet 3 | description: Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0). 4 | --- 5 | 6 | 7 | Python hash() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the hash value of the object (if it has one). Hash values are integers. They are used to quickly compare dictionary keys during a dictionary lookup. Numeric values that compare equal have the same hash value (even if they are of different types, as is the case for 1 and 1.0). 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> hash(1) 23 | # 1 24 | >>> hash('1') 25 | # -3658718886659147670 26 | >>> hash('10') 27 | # 5216539490891759533 28 | ``` 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /docs/builtin/hex.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python hex() built-in function - Python Cheatsheet 3 | description: Convert an integer number to a lowercase hexadecimal string prefixed with “0x”. If x is not a Python int object, it has to define an __index__() method that returns an integer. 4 | --- 5 | 6 | 7 | Python hex() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Convert an integer number to a lowercase hexadecimal string prefixed with “0x”. If x is not a Python int object, it has to define an __index__() method that returns an integer. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> hex(1) 23 | # '0x1' 24 | >>> hex(10) 25 | # '0xa' 26 | >>> hex(100) 27 | # '0x64' 28 | >>> hex(1000) 29 | # '0x3e8' 30 | ``` 31 | -------------------------------------------------------------------------------- /docs/builtin/id.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python id() built-in function - Python Cheatsheet 3 | description: Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. 4 | --- 5 | 6 | 7 | Python id() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the “identity” of an object. This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> id(1) 23 | # 9788960 24 | >>> id('1') 25 | # 140269689726000 26 | >>> id([1, 2]) 27 | # 140269672924928 28 | ``` 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /docs/builtin/import.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python __import__() built-in function - Python Cheatsheet 3 | description: This function is invoked by the import statement. It can be replaced [...] in order to change semantics of the import statement, but doing so is strongly discouraged as it is usually simpler to use import hooks [...]. Direct use of __import__() is also discouraged in favor of importlib.import_module(). 4 | --- 5 | 6 | 7 | Python `__import__` built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | This function is invoked by the import statement. It can be replaced [...] in order to change semantics of the import statement, but doing so is strongly discouraged as it is usually simpler to use import hooks [...]. Direct use of __import__() is also discouraged in favor of importlib.import_module(). 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/builtin/input.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python input() built-in function - Python Cheatsheet 3 | description: If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. 4 | --- 5 | 6 | 7 | Python input() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | This function takes the input from the user and converts it into a string: 22 | 23 | ```python 24 | >>> print('What is your name?') # ask for their name 25 | >>> my_name = input() 26 | >>> print('Hi, {}'.format(my_name)) 27 | # What is your name? 28 | # Martha 29 | # Hi, Martha 30 | ``` 31 | 32 | `input()` can also set a default message without using `print()`: 33 | 34 | ```python 35 | >>> my_name = input('What is your name? ') # default message 36 | >>> print('Hi, {}'.format(my_name)) 37 | # What is your name? Martha 38 | # Hi, Martha 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/builtin/int.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python int() built-in function - Python Cheatsheet 3 | description: Return an integer object constructed from a number or string x, or return 0 if no arguments are given. 4 | --- 5 | 6 | 7 | Python int() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return an integer object constructed from a number or string x, or return 0 if no arguments are given. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> # transform a string to an integer 23 | >>> from_integer = int('29') 24 | >>> from_integer 25 | # 29 26 | >>> type(from_integer) 27 | # 28 | 29 | >>> # transform a float to integer 30 | >>> from_float = int(-3.14) 31 | >>> from_float 32 | # -3 33 | >>> type(from_float) 34 | # 35 | 36 | >>> # return an empty string 37 | >>> int() 38 | # 0 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/builtin/isinstance.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python isinstance() built-in function - Python Cheatsheet 3 | description: Return True if the object argument is an instance of the classinfo argument, or of a (direct, indirect, or virtual) subclass thereof. If object is not an object of the given type, the function always returns False. If classinfo is a tuple of type objects (or recursively, other such tuples) or a Union Type of multiple types, return True if object is an instance of any of the types. If classinfo is not a type or tuple of types and such tuples, a TypeError exception is raised. 4 | --- 5 | 6 | 7 | Python isinstance() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return True if the object argument is an instance of the classinfo argument, or of a (direct, indirect, or virtual) subclass thereof. If object is not an object of the given type, the function always returns False. If classinfo is a tuple of type objects (or recursively, other such tuples) or a Union Type of multiple types, return True if object is an instance of any of the types. If classinfo is not a type or tuple of types and such tuples, a TypeError exception is raised. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> isinstance(1, int) 23 | # True 24 | >>> isinstance(1, str) 25 | # False 26 | ``` 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/builtin/issubclass.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python issubclass() built-in function - Python Cheatsheet 3 | description: Return True if class is a subclass (direct, indirect, or virtual) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects (or recursively, other such tuples) or a Union Type, in which case return True if class is a subclass of any entry in classinfo. In any other case, a TypeError exception is raised. 4 | --- 5 | 6 | 7 | Python issubclass() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return True if class is a subclass (direct, indirect, or virtual) of classinfo. A class is considered a subclass of itself. classinfo may be a tuple of class objects (or recursively, other such tuples) or a Union Type, in which case return True if class is a subclass of any entry in classinfo. In any other case, a TypeError exception is raised. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | class First: 23 | pass 24 | 25 | class Second(First): 26 | pass 27 | 28 | print(issubclass(Second, First)) # True 29 | print(issubclass(First, Second)) # False 30 | ``` 31 | -------------------------------------------------------------------------------- /docs/builtin/iter.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python iter() built-in function - Python Cheatsheet 3 | description: Return an iterator object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, object must be a collection object which supports the iterable protocol, or it must support the sequence protocol. If it does not support either of those protocols, TypeError is raised. 4 | --- 5 | 6 | 7 | Python iter() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return an iterator object. The first argument is interpreted very differently depending on the presence of the second argument. Without a second argument, object must be a collection object which supports the iterable protocol, or it must support the sequence protocol. If it does not support either of those protocols, TypeError is raised. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> i = iter([1, 2, 3]) 23 | >>> i 24 | # 25 | >>> i.__next__() 26 | # 1 27 | >>> i.__next__() 28 | # 2 29 | >>> i.__next__() 30 | # 3 31 | ``` 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /docs/builtin/len.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python len() built-in function - Python Cheatsheet 3 | description: Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set). 4 | --- 5 | 6 | 7 | Python len() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the length (the number of items) of an object. The argument may be a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set). 16 | 17 | 18 | 19 | ## Example 20 | 21 | Return the the number of items of an object: 22 | 23 | ```python 24 | >>> len('hello') 25 | # 5 26 | 27 | >>> len(['cat', 3, 'dog']) 28 | # 3 29 | ``` 30 | 31 | ## Test of emptiness 32 | 33 | 34 | Test of emptiness 35 | 36 | Test of emptiness of strings, lists, dictionaries, etc., should not use 37 | len, but prefer direct boolean evaluation. 38 | 39 | 40 | 41 | ```python 42 | >>> a = [1, 2, 3] 43 | 44 | # bad 45 | >>> if len(a) > 0: # evaluates to True 46 | ... print("the list is not empty!") 47 | ... 48 | # the list is not empty! 49 | 50 | # good 51 | >>> if a: # evaluates to True 52 | ... print("the list is not empty!") 53 | ... 54 | # the list is not empty! 55 | ``` 56 | -------------------------------------------------------------------------------- /docs/builtin/list.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python list() built-in function - Python Cheatsheet 3 | description: Rather than being a function, list is actually a mutable sequence type, as documented in Lists and Sequence Types — list, tuple, range. 4 | --- 5 | 6 | 7 | Python list() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Rather than being a function, list is actually a mutable sequence type, as documented in Lists and Sequence Types — list, tuple, range. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> l = list() 23 | >>> l 24 | # [] 25 | >>> l.append(1) 26 | >>> l.append(2) 27 | >>> l 28 | # [1, 2] 29 | ``` 30 | -------------------------------------------------------------------------------- /docs/builtin/locals.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python locals() built-in function - Python Cheatsheet 3 | description: Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks. Note that at the module level, locals() and globals() are the same dictionary. 4 | --- 5 | 6 | 7 | Python locals() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Update and return a dictionary representing the current local symbol table. Free variables are returned by locals() when it is called in function blocks, but not in class blocks. Note that at the module level, locals() and globals() are the same dictionary. 16 | 17 | 18 | 19 | 20 | ## Example 21 | 22 | ```python 23 | def my_function(): 24 | name = "Jim" 25 | age = 35 26 | print(locals()) 27 | 28 | my_function() # {'name': 'Jim', 'age': 35} 29 | ``` 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /docs/builtin/max.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python max() built-in function - Python Cheatsheet 3 | description: Return the largest item in an iterable or the largest of two or more arguments. 4 | --- 5 | 6 | 7 | Python max() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the largest item in an iterable or the largest of two or more arguments. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> max([1, 2, 10, 40, 5]) 23 | # 40 24 | >>> max((1, 2, 10, 40, 5)) 25 | # 40 26 | ``` 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/builtin/memoryview.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python memoryview() built-in function - Python Cheatsheet 3 | description: Return a “memory view” object created from the given argument. See Memory Views for more information. 4 | --- 5 | 6 | 7 | Python memoryview() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a “memory view” object created from the given argument. See Memory Views for more information. 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/builtin/min.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python min() built-in function - Python Cheatsheet 3 | description: Return the smallest item in an iterable or the smallest of two or more arguments. 4 | --- 5 | 6 | 7 | Python min() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the smallest item in an iterable or the smallest of two or more arguments. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> min([1, 2, 10, 40, 5]) 23 | # 1 24 | >>> min((1, 2, 10, 40, 5)) 25 | # 1 26 | ``` 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/builtin/next.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python next() built-in function - Python Cheatsheet 3 | description: Retrieve the next item from the iterator by calling its __next__() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised. 4 | --- 5 | 6 | 7 | Python next() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Retrieve the next item from the iterator by calling its __next__() method. If default is given, it is returned if the iterator is exhausted, otherwise StopIteration is raised. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> i = iter([1, 2, 3]) 23 | >>> i 24 | # 25 | >>> next(i) 26 | # 1 27 | >>> next(i) 28 | # 2 29 | >>> next(i) 30 | # 3 31 | ``` 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /docs/builtin/object.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python object() built-in function - Python Cheatsheet 3 | description: Return a new featureless object. object is a base for all classes. It has methods that are common to all instances of Python classes. This function does not accept any arguments. 4 | --- 5 | 6 | 7 | Python object() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a new featureless object. object is a base for all classes. It has methods that are common to all instances of Python classes. This function does not accept any arguments. 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/builtin/oct.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python oct() built-in function - Python Cheatsheet 3 | description: Convert an integer number to an octal string prefixed with “0o”. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer. 4 | --- 5 | 6 | 7 | Python oct() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Convert an integer number to an octal string prefixed with “0o”. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> oct(1) 23 | # '0o1' 24 | >>> oct(10) 25 | # '0o12' 26 | >>> oct(100) 27 | # '0o144' 28 | >>> oct(1000) 29 | # '0o1750' 30 | ``` 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /docs/builtin/open.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python open() built-in function - Python Cheatsheet 3 | description: Open file and return a corresponding file object. If the file cannot be opened, an OSError is raised. See Reading and Writing Files for more examples of how to use this function. 4 | --- 5 | 6 | 7 | Python open() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Open file and return a corresponding file object. If the file cannot be opened, an OSError is raised. See Reading and Writing Files for more examples of how to use this function. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> spam = open('spam.txt', mode='x') 23 | >>> spam.write('My first line\n\n') 24 | >>> spam.close() 25 | # Opens a brand new file (in 'x' mode will throw if already exists) 26 | 27 | >>> with open('spam.txt', mode='a') as spam: 28 | ... spam.write('My second line') 29 | # Appends to file and automatically closes afterward 30 | 31 | >>> with open('spam.txt') as spam: 32 | ... content = spam.read() 33 | ... print(content) 34 | # My first line 35 | # 36 | # My second line 37 | ``` 38 | -------------------------------------------------------------------------------- /docs/builtin/ord.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python ord() built-in function - Python Cheatsheet 3 | description: Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. 4 | --- 5 | 6 | 7 | Python ord() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> ord('1') 23 | # 49 24 | >>> ord('a') 25 | # 97 26 | ``` 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/builtin/pow.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python pow() built-in function - Python Cheatsheet 3 | description: The pow() function returns the power of a number. 4 | --- 5 | 6 | 7 | Python pow() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | The pow() function returns the power of a number.It takes two or three arguments: 16 | pow(base, exp): Returns base raised to the power of exp (base ** exp). 17 | pow(base, exp, mod): Returns (base ** exp) % mod (for modular arithmetic). 18 | Result is computed more efficiently than base ** exp % mod, if mod arg is present. 19 | 20 | 21 | 22 | ## Example 23 | 24 | ```python 25 | # Basic exponentiation 26 | >>> pow(2, 3) 27 | # 8 28 | 29 | # Using three arguments (modular exponentiation) 30 | >>> pow(2, 3, 5) 31 | # 3 (since 2^3 = 8, and 8 % 5 = 3) 32 | 33 | # Works with negative exponents (returns float) 34 | >>> pow(2, -3) 35 | # 0.125 (since 2^(-3) = 1/8) 36 | ``` 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /docs/builtin/print.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python print() built-in function - Python Cheatsheet 3 | description: Print objects to the text stream file, separated by sep and followed by end. sep, end, file, and flush, if present, must be given as keyword arguments. 4 | --- 5 | 6 | 7 | Python print() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Print objects to the text stream file, separated by sep and followed by end. sep, end, file, and flush, if present, must be given as keyword arguments. 16 | 17 | 18 | 19 | The `print()` function writes the value of the argument(s) it is given. [...] it handles multiple arguments, floating point-quantities, and strings. Strings are printed without quotes, and a space is inserted between items, so you can format things nicely: 20 | 21 | ```python 22 | >>> print('Hello world!') 23 | # Hello world! 24 | 25 | >>> a = 1 26 | >>> print('Hello world!', a) 27 | # Hello world! 1 28 | ``` 29 | 30 | ## The end keyword 31 | 32 | The keyword argument `end` can be used to avoid the newline after the output, or end the output with a different string: 33 | 34 | ```python 35 | phrase = ['printed', 'with', 'a', 'dash', 'in', 'between'] 36 | >>> for word in phrase: 37 | ... print(word, end='-') 38 | ... 39 | # printed-with-a-dash-in-between- 40 | ``` 41 | 42 | ## The sep keyword 43 | 44 | The keyword `sep` specify how to separate the objects, if there is more than one: 45 | 46 | ```python 47 | print('cats', 'dogs', 'mice', sep=',') 48 | # cats,dogs,mice 49 | ``` 50 | -------------------------------------------------------------------------------- /docs/builtin/property.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python property() built-in function - Python Cheatsheet 3 | description: Return a property attribute. 4 | --- 5 | 6 | 7 | Python property() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a property attribute. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> property(1) 23 | # 24 | >>> property('1') 25 | # 26 | ``` 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/builtin/repr.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python repr() built-in function - Python Cheatsheet 3 | description: Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(); otherwise, the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a __repr__() method. 4 | --- 5 | 6 | 7 | Python repr() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(); otherwise, the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object. A class can control what this function returns for its instances by defining a __repr__() method. 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/builtin/reversed.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python reversed() built-in function - Python Cheatsheet 3 | description: Return a reverse iterator. seq must be an object which has a __reversed__() method or supports the sequence protocol (the __len__() method and the __getitem__() method with integer arguments starting at 0). 4 | --- 5 | 6 | 7 | Python reversed() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a reverse iterator. seq must be an object which has a __reversed__() method or supports the sequence protocol (the __len__() method and the __getitem__() method with integer arguments starting at 0). 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> i = reversed([1, 2, 3]) 23 | >>> i.__next__() 24 | # 3 25 | >>> i.__next__() 26 | # 2 27 | >>> i.__next__() 28 | # 1 29 | >>> i 30 | # 31 | ``` 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /docs/builtin/round.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python round() built-in function - Python Cheatsheet 3 | description: Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input. 4 | --- 5 | 6 | 7 | Python round() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return number rounded to ndigits precision after the decimal point. If ndigits is omitted or is None, it returns the nearest integer to its input. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> round(1.4) 23 | # 1 24 | >>> round(1.5) 25 | # 2 26 | >>> round(2.1) 27 | # 2 28 | >>> round(2.9) 29 | # 3 30 | >>> round(2/3, ndigits=3) 31 | # 0.667 32 | ``` 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/builtin/set.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python set() built-in function - Python Cheatsheet 3 | description: Return a new set object, optionally with elements taken from iterable. set is a built-in class. See set and Set Types — set, frozenset for documentation about this class. 4 | --- 5 | 6 | 7 | Python set() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a new set object, optionally with elements taken from iterable. set is a built-in class. See set and Set Types — set, frozenset for documentation about this class. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> s = set() 23 | >>> s 24 | # set() 25 | >>> type(s) 26 | # 27 | ``` 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /docs/builtin/setattr.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python setattr() built-in function - Python Cheatsheet 3 | description: This is the counterpart of getattr(). The arguments are an object, a string, and an arbitrary value. The string may name an existing attribute or a new attribute. The function assigns the value to the attribute, provided the object allows it. For example, setattr(x, 'foobar', 123) is equivalent to x.foobar = 123. 4 | --- 5 | 6 | 7 | Python setattr() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | This is the counterpart of getattr(). The arguments are an object, a string, and an arbitrary value. The string may name an existing attribute or a new attribute. The function assigns the value to the attribute, provided the object allows it. For example, setattr(x, 'foobar', 123) is equivalent to x.foobar = 123. 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/builtin/slice.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python slice() built-in function - Python Cheatsheet 3 | description: Return a slice object representing the set of indices specified by range(start, stop, step). The start and step arguments default to None. Slice objects have read-only data attributes start, stop, and step which merely return the argument values (or their default). 4 | --- 5 | 6 | 7 | Python slice() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a slice object representing the set of indices specified by range(start, stop, step). The start and step arguments default to None. Slice objects have read-only data attributes start, stop, and step which merely return the argument values (or their default). 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> furniture = ['table', 'chair', 'rack', 'shelf'] 23 | 24 | >>> furniture[0:4] 25 | # ['table', 'chair', 'rack', 'shelf'] 26 | 27 | >>> furniture[1:3] 28 | # ['chair', 'rack'] 29 | 30 | >>> furniture[0:-1] 31 | # ['table', 'chair', 'rack'] 32 | 33 | >>> furniture[:2] 34 | # ['table', 'chair'] 35 | 36 | >>> furniture[1:] 37 | # ['chair', 'rack', 'shelf'] 38 | 39 | >>> furniture[:] 40 | # ['table', 'chair', 'rack', 'shelf'] 41 | ``` 42 | 43 | Slicing the complete list will perform a copy: 44 | 45 | ```python 46 | >>> spam2 = spam[:] 47 | # ['cat', 'bat', 'rat', 'elephant'] 48 | 49 | >>> spam.append('dog') 50 | >>> spam 51 | # ['cat', 'bat', 'rat', 'elephant', 'dog'] 52 | 53 | >>> spam2 54 | # ['cat', 'bat', 'rat', 'elephant'] 55 | ``` 56 | -------------------------------------------------------------------------------- /docs/builtin/sorted.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python sorted() built-in function - Python Cheatsheet 3 | description: Return a new sorted list from the items in iterable. 4 | --- 5 | 6 | 7 | Python sorted() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a new sorted list from the items in iterable. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> sorted([1, 2, 3, 7, 4]) 23 | # [1, 2, 3, 4, 7] 24 | 25 | >>> sorted(['a', 'h', 'e']) 26 | # ['a', 'e', 'h'] 27 | 28 | >>> sorted([1, 2, 3, 7, 4], reverse=True) 29 | # [7, 4, 3, 2, 1] 30 | 31 | >>> sorted(['a', 'h', 'e'], reverse=True) 32 | # ['h', 'e', 'a'] 33 | ``` 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /docs/builtin/staticmethod.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python staticmethod() built-in function - Python Cheatsheet 3 | description: Transform a method into a static method. 4 | --- 5 | 6 | 7 | Python staticmethod() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Transform a method into a static method. 16 | 17 | 18 | The @staticmethod is a function decorator that will transform a class method into a static method that functions in a similar behavior to a C++ or other oop language static methods. 19 | 20 | You can turn a class method into a static method by applying the @staticmethod decorator to a function in a class. For example: 21 | 22 | ```python 23 | >>> class C: 24 | >>> @staticmethod 25 | >>> def function(): .... 26 | ``` 27 | 28 | Static methods can be called on the class itself like 29 | 30 | ```python 31 | >>> class Class: 32 | >>> @staticmethod 33 | >>> def function(): 34 | >>> print("X") 35 | >>> 36 | >>> Class.function() 37 | >>> # X 38 | ``` 39 | 40 | Or on an instance of the class like 41 | 42 | ```python 43 | >>> class Class: 44 | >>> @staticmethod 45 | >>> def function(): 46 | >>> print("X") 47 | >>> 48 | >>> new_class = Class() 49 | >>> new_class.function() 50 | >>> # X 51 | ``` 52 | 53 | The @staticmethod is in the form of a decorator the basics being it is a function that will return another function. This will be documented at a later time. 54 | -------------------------------------------------------------------------------- /docs/builtin/str.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python str() built-in function - Python Cheatsheet 3 | description: Return a string version of object. If object is not provided, returns the empty string. Otherwise, the behavior of str() depends on whether encoding or errors is given. 4 | --- 5 | 6 | 7 | Python str() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a string version of object. If object is not provided, returns the empty string. Otherwise, the behavior of str() depends on whether encoding or errors is given. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> # transform an integer to a string 23 | >>> from_integer = str(29) 24 | >>> from_integer 25 | # '29' 26 | >>> type(from_integer) 27 | # 28 | 29 | >>> # transform a float to string 30 | >>> from_float = str(-3.14) 31 | >>> from_float 32 | # '-3.14' 33 | >>> type(from_float) 34 | # 35 | 36 | >>> # return an empty string 37 | >>> str() 38 | # '' 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/builtin/sum.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python sum() built-in function - Python Cheatsheet 3 | description: Sums start and the items of an iterable from left to right and returns the total. The iterable’s items are normally numbers, and the start value is not allowed to be a string. 4 | --- 5 | 6 | 7 | Python sum() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Sums start and the items of an iterable from left to right and returns the total. The iterable’s items are normally numbers, and the start value is not allowed to be a string. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> sum([2, 4, 6]) 23 | # 12 24 | >>> sum([10, 10, 10]) 25 | # 30 26 | ``` 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/builtin/super.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python super() built-in function - Python Cheatsheet 3 | description: Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. 4 | --- 5 | 6 | 7 | Python super() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/builtin/tuple.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python tuple() built-in function - Python Cheatsheet 3 | description: Rather than being a function, tuple is actually an immutable sequence type, as documented in Tuples and Sequence Types — list, tuple, range. 4 | --- 5 | 6 | 7 | Python tuple() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Rather than being a function, tuple is actually an immutable sequence type, as documented in Tuples and Sequence Types — list, tuple, range. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> t = tuple() 23 | >>> type(t) 24 | # 25 | >>> t 26 | # () 27 | 28 | >>> l = [1, 2, 3] 29 | >>> tuple(l) 30 | # (1, 2, 3) 31 | ``` 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /docs/builtin/type.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python type() built-in function - Python Cheatsheet 3 | description: With one argument, return the type of an object. The return value is a type object and generally the same object as returned by object.__class__. 4 | --- 5 | 6 | 7 | Python type() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | With one argument, return the type of an object. The return value is a type object and generally the same object as returned by object.__class__. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | >>> type('span') 23 | # 24 | 25 | >>> type(99) 26 | # 27 | 28 | >>> type(1.1) 29 | # 30 | 31 | >>> type([1, 2]) 32 | # 33 | 34 | >>> type((1, 2)) 35 | # 36 | 37 | >>> type({1, 2}) 38 | # 39 | 40 | >>> type({'a': 1, 'b': 2}) 41 | # 42 | ``` 43 | -------------------------------------------------------------------------------- /docs/builtin/vars.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python vars() built-in function - Python Cheatsheet 3 | description: Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute. 4 | --- 5 | 6 | 7 | Python vars() built-in function 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__ attribute. 16 | 17 | 18 | 19 | ## Examples 20 | 21 | ```python 22 | 23 | class Person: 24 | def __init__(self, name, age): 25 | self.name = name 26 | self.age = age 27 | my_person = Person("Dwight", 35) 28 | 29 | my_vars = vars(my_person) 30 | 31 | print(my_vars) 32 | # {'name': 'Dwight', 'age': 35} 33 | ``` 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/cheatsheet/dataclasses.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python Dataclasses - Python Cheatsheet 3 | description: Dataclasses are python classes, but are suited for storing data objects. This module provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes. 4 | --- 5 | 6 | 7 | Python Dataclasses 8 | 9 | 10 | `Dataclasses` are python classes, but are suited for storing data objects. 11 | This module provides a decorator and functions for automatically adding generated special methods such as `__init__()` and `__repr__()` to user-defined classes. 12 | 13 | ## Features 14 | 15 | 1. They store data and represent a certain data type. Ex: A number. For people familiar with ORMs, a model instance is a data object. It represents a specific kind of entity. It holds attributes that define or represent the entity. 16 | 17 | 2. They can be compared to other objects of the same type. Ex: A number can be greater than, less than, or equal to another number. 18 | 19 | Python 3.7 provides a decorator dataclass that is used to convert a class into a dataclass. 20 | 21 | ```python 22 | >>> class Number: 23 | ... def __init__(self, val): 24 | ... self.val = val 25 | ... 26 | >>> obj = Number(2) 27 | >>> obj.val 28 | # 2 29 | ``` 30 | 31 | with dataclass 32 | 33 | ```python 34 | >>> @dataclass 35 | ... class Number: 36 | ... val: int 37 | ... 38 | >>> obj = Number(2) 39 | >>> obj.val 40 | # 2 41 | ``` 42 | 43 | ## Default values 44 | 45 | It is easy to add default values to the fields of your data class. 46 | 47 | ```python 48 | >>> @dataclass 49 | ... class Product: 50 | ... name: str 51 | ... count: int = 0 52 | ... price: float = 0.0 53 | ... 54 | >>> obj = Product("Python") 55 | >>> obj.name 56 | # Python 57 | 58 | >>> obj.count 59 | # 0 60 | 61 | >>> obj.price 62 | # 0.0 63 | ``` 64 | 65 | ## Type hints 66 | 67 | It is mandatory to define the data type in dataclass. However, If you would rather not specify the datatype then, use `typing.Any`. 68 | 69 | ```python 70 | >>> from dataclasses import dataclass 71 | >>> from typing import Any 72 | 73 | >>> @dataclass 74 | ... class WithoutExplicitTypes: 75 | ... name: Any 76 | ... value: Any = 42 77 | ``` 78 | -------------------------------------------------------------------------------- /docs/cheatsheet/json-yaml.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python Json and YAML - Python Cheatsheet 3 | description: JSON stands for JavaScript Object Notation and is a lightweight format for storing and transporting data. Json is often used when data is sent from a server to a web page. 4 | --- 5 | 6 | 7 | JSON and YAML 8 | 9 | 10 | ## JSON 11 | 12 | JSON stands for JavaScript Object Notation and is a lightweight format for storing and transporting data. Json is often used when data is sent from a server to a web page. 13 | 14 | ```python 15 | >>> import json 16 | >>> with open("filename.json", "r") as f: 17 | ... content = json.load(f) 18 | ``` 19 | 20 | Write a JSON file with: 21 | 22 | ```python 23 | >>> import json 24 | 25 | >>> content = {"name": "Joe", "age": 20} 26 | >>> with open("filename.json", "w") as f: 27 | ... json.dump(content, f, indent=2) 28 | ``` 29 | 30 | ## YAML 31 | 32 | Compared to JSON, YAML allows a much better human maintainability and gives ability to add comments. It is a convenient choice for configuration files where a human will have to edit. 33 | 34 | There are two main libraries allowing access to YAML files: 35 | 36 | - [PyYaml](https://pypi.python.org/pypi/PyYAML) 37 | - [Ruamel.yaml](https://pypi.python.org/pypi/ruamel.yaml) 38 | 39 | Install them using `pip install` in your virtual environment. 40 | 41 | The first one is easier to use but the second one, Ruamel, implements much better the YAML 42 | specification, and allow for example to modify a YAML content without altering comments. 43 | 44 | Open a YAML file with: 45 | 46 | ```python 47 | >>> from ruamel.yaml import YAML 48 | 49 | >>> with open("filename.yaml") as f: 50 | ... yaml=YAML() 51 | ... yaml.load(f) 52 | ``` 53 | 54 | ## Anyconfig 55 | 56 | [Anyconfig](https://pypi.python.org/pypi/anyconfig) is a very handy package, allowing to abstract completely the underlying configuration file format. It allows to load a Python dictionary from JSON, YAML, TOML, and so on. 57 | 58 | Install it with: 59 | 60 | ```bash 61 | pip install anyconfig 62 | ``` 63 | 64 | Usage: 65 | 66 | ```python 67 | >>> import anyconfig 68 | >>> conf1 = anyconfig.load("/path/to/foo/conf.d/a.yml") 69 | ``` 70 | -------------------------------------------------------------------------------- /docs/cheatsheet/main.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python Main function - Python Cheatsheet 3 | description: is the name of the scope in which top-level code executes. A module’s name is set equal to main when read from standard input, a script, or from an interactive prompt. 4 | --- 5 | 6 | 7 | Main top-level script environment 8 | 9 | 10 | ## What is it 11 | 12 | `__main__` is the name of the scope in which top-level code executes. 13 | A module’s **name** is set equal to `__main__` when read from standard input, a script, or from an interactive prompt. 14 | 15 | A module can discover whether it is running in the main scope by checking its own `__name__`, which allows a common idiom for conditionally executing code in a module. When it is run as a script or with `python -m` but not when it is imported: 16 | 17 | ```python 18 | >>> if __name__ == "__main__": 19 | ... # execute only if run as a script 20 | ... main() 21 | ``` 22 | 23 | For a package, the same effect can be achieved by including a **main**.py module, the contents of which will be executed when the module is run with -m. 24 | 25 | For example, we are developing a script designed to be used as a module, we should do: 26 | 27 | ```python 28 | >>> def add(a, b): 29 | ... return a+b 30 | ... 31 | >>> if __name__ == "__main__": 32 | ... add(3, 5) 33 | ``` 34 | 35 | ## Advantages 36 | 37 | 1. Every Python module has it’s `__name__` defined and if this is `__main__`, it implies that the module is run standalone by the user, and we can do corresponding appropriate actions. 38 | 2. If you import this script as a module in another script, the **name** is set to the name of the script/module. 39 | 3. Python files can act as either reusable modules, or as standalone programs. 40 | 4. `if __name__ == "__main__":` is used to execute some code only if the file is run directly, and is not being imported. 41 | -------------------------------------------------------------------------------- /docs/cheatsheet/reading-and-writing-files.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Reading and writing files - Python Cheatsheet 3 | description: To read/write to a file in Python, you will want to use the with statement, which will close the file for you after you are done, managing the available resources for you. 4 | --- 5 | 6 | 7 | Reading and Writing Files 8 | 9 | 10 | ## The file Reading/Writing process 11 | 12 | To read/write to a file in Python, you will want to use the `with` 13 | statement, which will close the file for you after you are done, managing the available resources for you. 14 | 15 | ## Opening and reading files 16 | 17 | The `open` function opens a file and return a corresponding file object. 18 | 19 | ```python 20 | >>> with open('C:\\Users\\your_home_folder\\hi.txt') as hello_file: 21 | ... hello_content = hello_file.read() 22 | ... 23 | >>> hello_content 24 | 'Hello World!' 25 | ``` 26 | 27 | Alternatively, you can use the _readlines()_ method to get a list of string values from the file, one string for each line of text: 28 | 29 | ```python 30 | >>> with open('sonnet29.txt') as sonnet_file: 31 | ... sonnet_file.readlines() 32 | ... 33 | # [When, in disgrace with fortune and men's eyes,\n', 34 | # ' I all alone beweep my outcast state,\n', 35 | # And trouble deaf heaven with my bootless cries,\n', And 36 | # look upon myself and curse my fate,'] 37 | ``` 38 | 39 | You can also iterate through the file line by line: 40 | 41 | ```python 42 | >>> with open('sonnet29.txt') as sonnet_file: 43 | ... for line in sonnet_file: 44 | ... print(line, end='') 45 | ... 46 | # When, in disgrace with fortune and men's eyes, 47 | # I all alone beweep my outcast state, 48 | # And trouble deaf heaven with my bootless cries, 49 | # And look upon myself and curse my fate, 50 | ``` 51 | 52 | ## Writing to files 53 | 54 | ```python 55 | >>> with open('bacon.txt', 'w') as bacon_file: 56 | ... bacon_file.write('Hello world!\n') 57 | ... 58 | # 13 59 | 60 | >>> with open('bacon.txt', 'a') as bacon_file: 61 | ... bacon_file.write('Bacon is not a vegetable.') 62 | ... 63 | # 25 64 | 65 | >>> with open('bacon.txt') as bacon_file: 66 | ... content = bacon_file.read() 67 | ... 68 | >>> print(content) 69 | # Hello world! 70 | # Bacon is not a vegetable. 71 | ``` 72 | -------------------------------------------------------------------------------- /docs/modules/copy-module.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python Copy Module - Python Cheatsheet 3 | description: Copy Module is a set of functions that are related to copying different elements of a list, objects, arrays, etc. It can be used to create shallow copies as well as deep copies. 4 | --- 5 | 6 | 7 | Python Copy Module 8 | 9 | 10 | Copy Module is a set of functions that are related to copying different elements of a list, objects, arrays, etc. It can be used to create shallow copies as well as deep copies. 11 | 12 | 13 | 14 | From the Python 3 documentation 15 | 16 | 17 | Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed so one can change one copy without changing the other. This module provides generic shallow and deep copy operations. 18 | 19 | 20 | 21 | ## Shallow copy operations 22 | 23 | Shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original. 24 | 25 | copy.copy(x) 26 | Return a shallow copy of x. 27 | 28 | ```python 29 | >>> import copy 30 | >>> a = [[1],[2],[3]] 31 | >>> b = copy.copy(a) ## this will copy the list a to list b 32 | 33 | >>> a 34 | #[[1], [2], [3]] 35 | >>> b 36 | #[[1], [2], [3]] 37 | ``` 38 | ### Without importing copy module you can't use it 39 | 40 | ```python 41 | # Traceback (most recent call last): 42 | # File "", line 1, in 43 | # NameError: name 'copy' is not defined 44 | ``` 45 | ## Deep copy operations 46 | 47 | A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original. 48 | 49 | copy.deepcopy(x[, memo]) 50 | Return a deep copy of x. 51 | 52 | ```python 53 | >>> import copy 54 | >>> a = [[1],[2],[3]] 55 | >>> b = copy.deepcopy(a) ## this will copy the list a to list b 56 | 57 | >>> a[0][0] = 0 58 | >>> a[1] = None 59 | 60 | >>> a 61 | #[[0], None, [3]] 62 | >>> b 63 | #[[1], [2], [3]] 64 | ``` -------------------------------------------------------------------------------- /docs/modules/shelve-module.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Python Shelve Module - Python Cheatsheet 3 | description: A “shelf” is a persistent, dictionary-like object. in a shelf can be essentially arbitrary Python objects — anything that the pickle module can handle. 4 | --- 5 | 6 | 7 | Python Shelve Module 8 | 9 | 10 | 11 | 12 | From the Python 3 documentation 13 | 14 | 15 | A “shelf” is a persistent, dictionary-like object. The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects — anything that the pickle module can handle. This includes most class instances, recursive data types, and objects containing lots of shared sub-objects. The keys are ordinary strings. 16 | 17 | 18 | 19 | ## Save variables 20 | 21 | ```python 22 | >>> import shelve 23 | 24 | >>> wife = ['Pretty', 'Lovely', 'Nice'] 25 | >>> with shelve.open('mydata') as shelf_file: 26 | ... shelf_file['wife'] = wife 27 | ``` 28 | 29 | ## Open and read variables 30 | 31 | ```python 32 | >>> with shelve.open('mydata') as shelf_file: 33 | ... print(type(shelf_file)) 34 | ... print(shelf_file['wife']) 35 | ... 36 | # 37 | # ['Pretty', 'Lovely', 'Nice'] 38 | ``` 39 | 40 | Just like dictionaries, `shelf` values have `keys()` and `values()` methods that will return list-like values of the keys and values in the shelf. Since these methods return list-like values instead of true lists, you should pass them to the `list()` function to get them in list form. 41 | 42 | ```python 43 | >>> with shelve.open('mydata') as shelf_file: 44 | ... print(list(shelf_file.keys())) 45 | ... print(list(shelf_file.values())) 46 | ... 47 | # ['wife'] 48 | # [['Pretty', 'Lovely', 'Nice']] 49 | ``` 50 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 15 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build.environment] 2 | # bypass npm auto install 3 | NPM_FLAGS = "--version" 4 | NODE_VERSION = "16" 5 | 6 | [build] 7 | publish = "dist" 8 | command = "npx pnpm i --store=node_modules/.pnpm-store && npx pnpm run build" 9 | 10 | [[redirects]] 11 | from = "/*" 12 | to = "/index.html" 13 | status = 200 14 | 15 | [[headers]] 16 | for = "/manifest.webmanifest" 17 | [headers.values] 18 | Content-Type = "application/manifest+json" 19 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /public/_headers: -------------------------------------------------------------------------------- 1 | /assets/* 2 | cache-control: max-age=31536000 3 | cache-control: immutable 4 | -------------------------------------------------------------------------------- /public/_redirects: -------------------------------------------------------------------------------- 1 | /api/* https://api.curated.co/api/v3/:splat 200 2 | /_ /index.html 200 3 | /\* /index.html 404 -------------------------------------------------------------------------------- /public/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/android-chrome-192x192.png -------------------------------------------------------------------------------- /public/android-chrome-384x384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/android-chrome-384x384.png -------------------------------------------------------------------------------- /public/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/android-chrome-512x512.png -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/apple-touch-icon.png -------------------------------------------------------------------------------- /public/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | #da532c 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /public/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/favicon-16x16.png -------------------------------------------------------------------------------- /public/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/favicon-32x32.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/favicon.ico -------------------------------------------------------------------------------- /public/fonts/Inter-italic.var.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/fonts/Inter-italic.var.woff2 -------------------------------------------------------------------------------- /public/fonts/Inter-roman.var.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/fonts/Inter-roman.var.woff2 -------------------------------------------------------------------------------- /public/fonts/lexend.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/fonts/lexend.woff2 -------------------------------------------------------------------------------- /public/googleccbf6035fc9d727f.html: -------------------------------------------------------------------------------- 1 | google-site-verification: googleccbf6035fc9d727f.html -------------------------------------------------------------------------------- /public/icons/favicon.svg: -------------------------------------------------------------------------------- 1 | 11 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /public/mstile-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/mstile-144x144.png -------------------------------------------------------------------------------- /public/mstile-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/mstile-150x150.png -------------------------------------------------------------------------------- /public/mstile-310x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/mstile-310x150.png -------------------------------------------------------------------------------- /public/mstile-310x310.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/mstile-310x310.png -------------------------------------------------------------------------------- /public/mstile-70x70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/mstile-70x70.png -------------------------------------------------------------------------------- /public/pylogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/pylogo.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Allow: / -------------------------------------------------------------------------------- /public/safari-pinned-tab.svg: -------------------------------------------------------------------------------- 1 | Created by potrace 1.14, written by Peter Selinger 2001-2017 -------------------------------------------------------------------------------- /public/screenshots/dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/screenshots/dark.png -------------------------------------------------------------------------------- /public/screenshots/frame_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/screenshots/frame_dark.png -------------------------------------------------------------------------------- /public/screenshots/frame_generic_dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/screenshots/frame_generic_dark.png -------------------------------------------------------------------------------- /public/screenshots/frame_generic_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/screenshots/frame_generic_light.png -------------------------------------------------------------------------------- /public/screenshots/frame_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/screenshots/frame_light.png -------------------------------------------------------------------------------- /public/screenshots/light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/screenshots/light.png -------------------------------------------------------------------------------- /public/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/android-chrome-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | }, 10 | { 11 | "src": "/android-chrome-384x384.png", 12 | "sizes": "384x384", 13 | "type": "image/png" 14 | } 15 | ], 16 | "theme_color": "#ffffff", 17 | "background_color": "#ffffff", 18 | "display": "standalone" 19 | } 20 | -------------------------------------------------------------------------------- /public/snake.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/social/social_banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/social/social_banner.png -------------------------------------------------------------------------------- /public/sponsor.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/sponsor.mp4 -------------------------------------------------------------------------------- /public/sponsors/kinsta/SVG/kinsta-mobile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/sponsors/kinsta/SVG/kinsta-mobile.png -------------------------------------------------------------------------------- /public/sponsors/kinsta/kinsta-logo-alpha-purple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/sponsors/kinsta/kinsta-logo-alpha-purple.png -------------------------------------------------------------------------------- /public/sponsors/kinsta/kinsta-logo-alpha-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/sponsors/kinsta/kinsta-logo-alpha-white.png -------------------------------------------------------------------------------- /public/sponsors/kinsta/kinsta-logo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/sponsors/kinsta/kinsta-logo1.png -------------------------------------------------------------------------------- /public/sponsors/kinsta/kinsta-logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/sponsors/kinsta/kinsta-logo2.png -------------------------------------------------------------------------------- /public/sponsors/kinsta/kinsta-logo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/sponsors/kinsta/kinsta-logo3.png -------------------------------------------------------------------------------- /public/sponsors/practity/practity.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/sponsors/practity/practity.webp -------------------------------------------------------------------------------- /public/user-avatars/Acumane.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/Acumane.png -------------------------------------------------------------------------------- /public/user-avatars/AdamRosas27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/AdamRosas27.png -------------------------------------------------------------------------------- /public/user-avatars/Arham-Fox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/Arham-Fox.png -------------------------------------------------------------------------------- /public/user-avatars/BenIsenstein.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/BenIsenstein.png -------------------------------------------------------------------------------- /public/user-avatars/CodeWithBishal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/CodeWithBishal.png -------------------------------------------------------------------------------- /public/user-avatars/DevGauravJoshi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/DevGauravJoshi.png -------------------------------------------------------------------------------- /public/user-avatars/Gaura.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/Gaura.png -------------------------------------------------------------------------------- /public/user-avatars/HasnatHridoy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/HasnatHridoy.png -------------------------------------------------------------------------------- /public/user-avatars/ImgBotApp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/ImgBotApp.png -------------------------------------------------------------------------------- /public/user-avatars/LairdStreak.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/LairdStreak.png -------------------------------------------------------------------------------- /public/user-avatars/MaT1g3R.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/MaT1g3R.png -------------------------------------------------------------------------------- /public/user-avatars/Matthew-Nicholson.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/Matthew-Nicholson.png -------------------------------------------------------------------------------- /public/user-avatars/MozarM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/MozarM.png -------------------------------------------------------------------------------- /public/user-avatars/PmS-crypto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/PmS-crypto.png -------------------------------------------------------------------------------- /public/user-avatars/QuarkZ26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/QuarkZ26.png -------------------------------------------------------------------------------- /public/user-avatars/RichardScottOZ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/RichardScottOZ.png -------------------------------------------------------------------------------- /public/user-avatars/SeaSide53.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/SeaSide53.png -------------------------------------------------------------------------------- /public/user-avatars/Sonatrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/Sonatrix.png -------------------------------------------------------------------------------- /public/user-avatars/Vishesh-dd4723.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/Vishesh-dd4723.png -------------------------------------------------------------------------------- /public/user-avatars/Yaya9256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/Yaya9256.png -------------------------------------------------------------------------------- /public/user-avatars/abdussalam02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/abdussalam02.png -------------------------------------------------------------------------------- /public/user-avatars/adeelmc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/adeelmc.png -------------------------------------------------------------------------------- /public/user-avatars/aloklal99.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/aloklal99.png -------------------------------------------------------------------------------- /public/user-avatars/alvyynm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/alvyynm.png -------------------------------------------------------------------------------- /public/user-avatars/asenov.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/asenov.png -------------------------------------------------------------------------------- /public/user-avatars/azanbinzahid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/azanbinzahid.png -------------------------------------------------------------------------------- /public/user-avatars/ckartchner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/ckartchner.png -------------------------------------------------------------------------------- /public/user-avatars/classic-arnold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/classic-arnold.png -------------------------------------------------------------------------------- /public/user-avatars/comrade5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/comrade5.png -------------------------------------------------------------------------------- /public/user-avatars/connected-tcaceres.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/connected-tcaceres.png -------------------------------------------------------------------------------- /public/user-avatars/damiankrolik.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/damiankrolik.png -------------------------------------------------------------------------------- /public/user-avatars/danielpclin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/danielpclin.png -------------------------------------------------------------------------------- /public/user-avatars/darkpixlz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/darkpixlz.png -------------------------------------------------------------------------------- /public/user-avatars/decodingchris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/decodingchris.png -------------------------------------------------------------------------------- /public/user-avatars/ehmsu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/ehmsu.png -------------------------------------------------------------------------------- /public/user-avatars/evanrrees.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/evanrrees.png -------------------------------------------------------------------------------- /public/user-avatars/fPkX6F1nGTX.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/fPkX6F1nGTX.png -------------------------------------------------------------------------------- /public/user-avatars/firdousmurtaza1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/firdousmurtaza1.png -------------------------------------------------------------------------------- /public/user-avatars/flymemoryRPA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/flymemoryRPA.png -------------------------------------------------------------------------------- /public/user-avatars/gaurav-jo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/gaurav-jo1.png -------------------------------------------------------------------------------- /public/user-avatars/gsemet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/gsemet.png -------------------------------------------------------------------------------- /public/user-avatars/gspagare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/gspagare.png -------------------------------------------------------------------------------- /public/user-avatars/gulu42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/gulu42.png -------------------------------------------------------------------------------- /public/user-avatars/hacktron95.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/hacktron95.png -------------------------------------------------------------------------------- /public/user-avatars/johntheholman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/johntheholman.png -------------------------------------------------------------------------------- /public/user-avatars/kakasahebKK.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/kakasahebKK.png -------------------------------------------------------------------------------- /public/user-avatars/kavin5kumar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/kavin5kumar.png -------------------------------------------------------------------------------- /public/user-avatars/lukaszwojcik89.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/lukaszwojcik89.png -------------------------------------------------------------------------------- /public/user-avatars/madeelchaudhary.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/madeelchaudhary.png -------------------------------------------------------------------------------- /public/user-avatars/matteodem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/matteodem.png -------------------------------------------------------------------------------- /public/user-avatars/michaelbaluja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/michaelbaluja.png -------------------------------------------------------------------------------- /public/user-avatars/mohammedalrawi98.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/mohammedalrawi98.png -------------------------------------------------------------------------------- /public/user-avatars/msohaib9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/msohaib9.png -------------------------------------------------------------------------------- /public/user-avatars/mu-us61.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/mu-us61.png -------------------------------------------------------------------------------- /public/user-avatars/noraa-july-stoke.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/noraa-july-stoke.png -------------------------------------------------------------------------------- /public/user-avatars/nugel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/nugel.png -------------------------------------------------------------------------------- /public/user-avatars/omerts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/omerts.png -------------------------------------------------------------------------------- /public/user-avatars/omii2k01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/omii2k01.png -------------------------------------------------------------------------------- /public/user-avatars/paulwongx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/paulwongx.png -------------------------------------------------------------------------------- /public/user-avatars/pranayat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/pranayat.png -------------------------------------------------------------------------------- /public/user-avatars/prashanthbhat203.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/prashanthbhat203.png -------------------------------------------------------------------------------- /public/user-avatars/pyxfluff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/pyxfluff.png -------------------------------------------------------------------------------- /public/user-avatars/qkniep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/qkniep.png -------------------------------------------------------------------------------- /public/user-avatars/qudongfang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/qudongfang.png -------------------------------------------------------------------------------- /public/user-avatars/rawatdev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/rawatdev.png -------------------------------------------------------------------------------- /public/user-avatars/rbuzzell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/rbuzzell.png -------------------------------------------------------------------------------- /public/user-avatars/richjohnsonxyz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/richjohnsonxyz.png -------------------------------------------------------------------------------- /public/user-avatars/roopeshvs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/roopeshvs.png -------------------------------------------------------------------------------- /public/user-avatars/sage-gendron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/sage-gendron.png -------------------------------------------------------------------------------- /public/user-avatars/samithamphk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/samithamphk.png -------------------------------------------------------------------------------- /public/user-avatars/senlog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/senlog.png -------------------------------------------------------------------------------- /public/user-avatars/shirinapr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/shirinapr.png -------------------------------------------------------------------------------- /public/user-avatars/skyunna.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/skyunna.png -------------------------------------------------------------------------------- /public/user-avatars/supersandra.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/supersandra.png -------------------------------------------------------------------------------- /public/user-avatars/szTheory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/szTheory.png -------------------------------------------------------------------------------- /public/user-avatars/techboy-coder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/techboy-coder.png -------------------------------------------------------------------------------- /public/user-avatars/thacer13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/thacer13.png -------------------------------------------------------------------------------- /public/user-avatars/thoughtworks-tcaceres.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/thoughtworks-tcaceres.png -------------------------------------------------------------------------------- /public/user-avatars/tomfun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/tomfun.png -------------------------------------------------------------------------------- /public/user-avatars/unixorn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/unixorn.png -------------------------------------------------------------------------------- /public/user-avatars/vaibhavb02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/vaibhavb02.png -------------------------------------------------------------------------------- /public/user-avatars/wilfredinni.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/wilfredinni.png -------------------------------------------------------------------------------- /public/user-avatars/wn9237.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/wn9237.png -------------------------------------------------------------------------------- /public/user-avatars/xcsnowcity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/xcsnowcity.png -------------------------------------------------------------------------------- /public/user-avatars/zdouble.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/public/user-avatars/zdouble.png -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /scripts/fetch-avatars.ts: -------------------------------------------------------------------------------- 1 | import { join, resolve } from 'pathe' 2 | import fs from 'fs-extra' 3 | import { ofetch } from 'ofetch' 4 | 5 | const docsDir = resolve(__dirname, '../') 6 | const pathContributors = resolve(docsDir, 'contributors/contributors.json') 7 | const dirAvatars = resolve(docsDir, 'public/user-avatars/') 8 | 9 | let contributors: string[] = [] 10 | 11 | async function download(url: string, fileName: string) { 12 | try { 13 | console.log('downloading', fileName) 14 | const image = await ofetch(url, { responseType: 'arrayBuffer' }) 15 | await fs.writeFile(fileName, Buffer.from(image)) 16 | } catch (e) { 17 | console.log('error downloading', fileName) 18 | } 19 | } 20 | 21 | export async function fetchAvatars() { 22 | await fs.ensureDir(dirAvatars) 23 | contributors = JSON.parse( 24 | await fs.readFile(pathContributors, { encoding: 'utf-8' }), 25 | ) 26 | 27 | await Promise.all( 28 | contributors.map((name) => 29 | download( 30 | `https://github.com/${name}.png?size=48`, 31 | join(dirAvatars, `${name}.png`), 32 | ), 33 | ), 34 | ) 35 | } 36 | -------------------------------------------------------------------------------- /scripts/fetch-contributors.ts: -------------------------------------------------------------------------------- 1 | import { promises as fs } from 'fs' 2 | import { ofetch } from 'ofetch' 3 | import { fetchAvatars } from './fetch-avatars' 4 | 5 | interface Contributor { 6 | login: string 7 | } 8 | 9 | async function fetchContributors(page = 1) { 10 | const collaborators: string[] = [] 11 | const data = 12 | (await ofetch( 13 | `https://api.github.com/repos/wilfredinni/python-cheatsheet/contributors?per_page=100&page=1`, 14 | { 15 | method: 'get', 16 | headers: { 17 | 'content-type': 'application/json', 18 | }, 19 | }, 20 | )) || [] 21 | collaborators.push(...data.map((i) => i.login)) 22 | const index = collaborators.indexOf('renovate[bot]') 23 | if (index > -1) collaborators.splice(index, 1) 24 | 25 | if (data.length === 100) { 26 | collaborators.push(...(await fetchContributors(page + 1))) 27 | } 28 | 29 | return collaborators 30 | } 31 | 32 | async function generate() { 33 | const collaborators = await fetchContributors() 34 | await fs.writeFile( 35 | './contributors/contributors.json', 36 | JSON.stringify(collaborators, null, 2), 37 | 'utf8', 38 | ) 39 | } 40 | 41 | const init = async () => { 42 | await generate() 43 | await fetchAvatars() 44 | } 45 | 46 | init() 47 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 10 | 11 | 41 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/098ebe01cf52f5b64529e131a1ef0713d1c4e243/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/BlogTitleHeader.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 49 | -------------------------------------------------------------------------------- /src/components/CarbonAds.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 48 | 49 | 61 | -------------------------------------------------------------------------------- /src/components/Contributors.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 28 | -------------------------------------------------------------------------------- /src/components/EmptySection.vue: -------------------------------------------------------------------------------- 1 | 15 | -------------------------------------------------------------------------------- /src/components/KinstaBanner.vue: -------------------------------------------------------------------------------- 1 | 62 | -------------------------------------------------------------------------------- /src/components/NetlifyBadge.vue: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /src/components/Prose.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 32 | -------------------------------------------------------------------------------- /src/components/icons/ArrowIcon.vue: -------------------------------------------------------------------------------- 1 | 57 | -------------------------------------------------------------------------------- /src/components/icons/BugIcon.vue: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /src/components/icons/EditIcon.vue: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /src/components/icons/GithubIcon.vue: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /src/components/icons/QuestionIcon.vue: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /src/components/layout/TheSidebarDesktop.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 23 | -------------------------------------------------------------------------------- /src/components/layout/TheSidebarNavigation.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 38 | -------------------------------------------------------------------------------- /src/components/layout/TheToc.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 55 | -------------------------------------------------------------------------------- /src/components/sponsors/VpsServer.vue: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /src/components/sponsors/kinsta.vue: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /src/components/sponsors/practity.vue: -------------------------------------------------------------------------------- 1 | 20 | -------------------------------------------------------------------------------- /src/components/ui/BaseBadge.vue: -------------------------------------------------------------------------------- 1 | 42 | -------------------------------------------------------------------------------- /src/components/ui/BaseBadgeNotice.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 37 | -------------------------------------------------------------------------------- /src/components/ui/BaseBadgeSecondary.vue: -------------------------------------------------------------------------------- 1 | 25 | -------------------------------------------------------------------------------- /src/components/ui/BaseBanner.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 63 | 64 | 69 | -------------------------------------------------------------------------------- /src/components/ui/BaseCustomizableLinkCard.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 33 | -------------------------------------------------------------------------------- /src/components/ui/BaseLinkCard.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 36 | -------------------------------------------------------------------------------- /src/components/ui/BasePagination.vue: -------------------------------------------------------------------------------- 1 | 31 | 32 | 62 | -------------------------------------------------------------------------------- /src/components/ui/BaseReaderMode.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 10 | -------------------------------------------------------------------------------- /src/components/ui/BaseTitle.vue: -------------------------------------------------------------------------------- 1 | 17 | 18 | 52 | 53 | 61 | -------------------------------------------------------------------------------- /src/components/ui/disclaimer/BaseDisclaimer.vue: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /src/components/ui/disclaimer/BaseDisclaimerContent.vue: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /src/components/ui/disclaimer/BaseDisclaimerTitle.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/components/ui/newBadge.vue: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /src/components/ui/table/BaseTable.vue: -------------------------------------------------------------------------------- 1 | 9 | 10 | 43 | -------------------------------------------------------------------------------- /src/components/ui/table/BaseTableItem.vue: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /src/components/ui/table/BaseTableRow.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/components/ui/warning/BaseWarning.vue: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /src/components/ui/warning/BaseWarningContent.vue: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /src/components/ui/warning/BaseWarningTitle.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/composables/carbon.ts: -------------------------------------------------------------------------------- 1 | export function useCarbon() { 2 | const route = useRoute() 3 | const reader = useReaderStore() 4 | 5 | const reload = ref(false) 6 | 7 | watch( 8 | computed(() => reader.isActive), 9 | () => { 10 | if (reader.isActive) { 11 | reload.value = true 12 | nextTick(() => (reload.value = false)) 13 | } 14 | } 15 | ) 16 | 17 | watch( 18 | computed(() => route.path), 19 | () => { 20 | reload.value = true 21 | nextTick(() => (reload.value = false)) 22 | } 23 | ) 24 | 25 | function reloadOn(time: number) { 26 | setInterval(function () { 27 | if (!reader.isActive) { 28 | reload.value = true 29 | nextTick(() => (reload.value = false)) 30 | } 31 | }, time) 32 | } 33 | 34 | return { reload, reloadOn } 35 | } 36 | -------------------------------------------------------------------------------- /src/composables/dark.ts: -------------------------------------------------------------------------------- 1 | export const isDark = useDark() 2 | export const toggleDark = useToggle(isDark) 3 | export const preferredDark = usePreferredDark() 4 | -------------------------------------------------------------------------------- /src/composables/meta.ts: -------------------------------------------------------------------------------- 1 | export function useMeta() { 2 | const route = useRoute() 3 | const base_url = import.meta.env.VITE_BASE_URL || 'localhost:3000' 4 | 5 | const description = 6 | 'Anyone can forget how to make character classes for a regex, slice a list or do a for loop. This cheat sheet tries to provide a basic reference for beginner and advanced developers, lower the entry barrier for newcomers and help veterans refresh the old tricks.' 7 | const cardImage = 8 | 'https://raw.githubusercontent.com/wilfredinni/python-cheatsheet/master/public/screenshots/dark.png' 9 | const themeColor = computed(() => (isDark.value ? '#1f2937' : '#ffffff')) 10 | const url = computed(() => `https://${base_url}${route.path}`) 11 | const keywords = [ 12 | 'python', 13 | 'cheatsheet', 14 | 'cheat', 15 | 'sheet', 16 | 'functions', 17 | 'args', 18 | 'kwargs', 19 | 'sets', 20 | 'dictionary', 21 | 'list', 22 | 'string', 23 | 'regular', 24 | 'expression', 25 | 'formatting', 26 | 'file', 27 | 'path', 28 | 'json', 29 | 'test', 30 | 'vscode', 31 | 'comprehension', 32 | 'exception', 33 | 'debugging', 34 | 'dataclasses', 35 | 'environments', 36 | 'flow control', 37 | 'itertools', 38 | ] 39 | 40 | const meta = { 41 | title: 'Python Cheatsheet - Python Cheatsheet', 42 | description, 43 | meta: [ 44 | { name: 'theme-color', content: themeColor }, 45 | { name: 'description', content: description }, 46 | { name: 'author', content: 'Python Cheatsheet' }, 47 | { name: 'keywords', content: keywords.join(', ') }, 48 | { property: 'og:title', content: 'Python Cheatsheet' }, 49 | { property: 'og:description', content: description }, 50 | { property: 'og:url', content: url }, 51 | { property: 'og:type', content: 'article' }, 52 | { property: 'og:image', content: cardImage }, 53 | { name: 'twitter:title', content: 'Python Cheatsheet' }, 54 | { name: 'twitter:description', content: 'The Python Cheatsheet' }, 55 | { name: 'twitter:image', content: cardImage }, 56 | { name: 'twitter:card', content: 'summary' }, 57 | ], 58 | link: [{ rel: 'canonical', href: url }], 59 | } 60 | 61 | return { meta, description } 62 | } 63 | -------------------------------------------------------------------------------- /src/composables/scroll.ts: -------------------------------------------------------------------------------- 1 | export function useScrollBehavior() { 2 | const router = useRouter() 3 | router.options.scrollBehavior = (to, _from, savedPosition) => { 4 | if (savedPosition) return savedPosition 5 | if (to.hash) return { el: to.hash, behavior: 'smooth' } 6 | else return { top: 0, behavior: 'smooth' } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/composables/toc.ts: -------------------------------------------------------------------------------- 1 | import type { Ref } from 'vue' 2 | import { breakpointsTailwind } from '@vueuse/core' 3 | 4 | export function useToc() { 5 | const breakpoints = useBreakpoints(breakpointsTailwind) 6 | const lgAndLarger = breakpoints.greater('lg') 7 | 8 | interface Toc { 9 | header: string 10 | id: string 11 | } 12 | 13 | const theToc: Ref = ref([]) 14 | const createToc = () => { 15 | const h2 = document.getElementsByTagName('h2') 16 | theToc.value = Array.from(h2).map((item) => { 17 | return { header: item.innerText, id: item.id } 18 | }) 19 | } 20 | 21 | const currentSection = ref('') 22 | const getObserver = () => { 23 | const observer = new IntersectionObserver( 24 | (entries) => { 25 | entries.forEach((entry) => { 26 | if (entry.intersectionRatio > 0) { 27 | currentSection.value = entry.target.getAttribute('id') as string 28 | } 29 | }) 30 | }, 31 | { 32 | rootMargin: '0px 0px -50% 0px', 33 | } 34 | ) 35 | document.querySelectorAll('article h2').forEach((section) => { 36 | observer.observe(section) 37 | }) 38 | } 39 | 40 | const initToc = () => { 41 | if (lgAndLarger.value) { 42 | createToc() 43 | getObserver() 44 | } 45 | } 46 | 47 | const route = useRoute() 48 | onMounted(() => { 49 | initToc() 50 | }) 51 | 52 | watch(route, () => { 53 | nextTick(() => { 54 | initToc() 55 | }) 56 | }) 57 | 58 | return { theToc, currentSection } 59 | } 60 | -------------------------------------------------------------------------------- /src/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare module '*.vue' { 4 | import type { DefineComponent } from 'vue' 5 | // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types 6 | const component: DefineComponent<{}, {}, any> 7 | export default component 8 | } 9 | -------------------------------------------------------------------------------- /src/layouts/article.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 39 | -------------------------------------------------------------------------------- /src/layouts/blog.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 34 | -------------------------------------------------------------------------------- /src/layouts/empty.vue: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /src/layouts/fullPage.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 54 | 55 | 60 | -------------------------------------------------------------------------------- /src/layouts/fullWidth.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 14 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { ViteSSG } from 'vite-ssg' 2 | import { setupLayouts } from 'virtual:generated-layouts' 3 | import generatedRoutes from '~pages' 4 | import App from './App.vue' 5 | import type { UserModule } from './types' 6 | 7 | import './styles/index.css' 8 | 9 | const routes = setupLayouts(generatedRoutes) 10 | 11 | // https://github.com/antfu/vite-ssg 12 | export const createApp = ViteSSG( 13 | App, 14 | { routes, base: import.meta.env.BASE_URL }, 15 | (ctx) => { 16 | // install all modules under `modules/` 17 | Object.values( 18 | import.meta.glob<{ install: UserModule }>('./modules/*.ts', { 19 | eager: true, 20 | }) 21 | ).forEach((i) => i.install?.(ctx)) 22 | } 23 | ) 24 | -------------------------------------------------------------------------------- /src/modules/analytics.ts: -------------------------------------------------------------------------------- 1 | import VueGtag from 'vue-gtag' 2 | import { type UserModule } from '~/types' 3 | 4 | export const install: UserModule = ({ app }) => { 5 | const inProduction = import.meta.env.VITE_IN_PRODUCTION 6 | if (inProduction === 'true') { 7 | const gTag = import.meta.env.VITE_GTAG || 'tag' 8 | app.use(VueGtag, { 9 | config: { id: gTag }, 10 | }) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/modules/pinia.ts: -------------------------------------------------------------------------------- 1 | import { createPinia } from 'pinia' 2 | import { type UserModule } from '~/types' 3 | 4 | // Setup Pinia 5 | // https://pinia.esm.dev/ 6 | export const install: UserModule = ({ isClient, initialState, app }) => { 7 | const pinia = createPinia() 8 | app.use(pinia) 9 | // Refer to 10 | // https://github.com/antfu/vite-ssg/blob/main/README.md#state-serialization 11 | // for other serialization strategies. 12 | if (isClient) pinia.state.value = initialState.pinia || {} 13 | else initialState.pinia = pinia.state.value 14 | } 15 | -------------------------------------------------------------------------------- /src/modules/pwa.ts: -------------------------------------------------------------------------------- 1 | import { type UserModule } from '~/types' 2 | 3 | // https://github.com/antfu/vite-plugin-pwa#automatic-reload-when-new-content-available 4 | export const install: UserModule = ({ isClient, router }) => { 5 | if (!isClient) return 6 | 7 | router 8 | .isReady() 9 | .then(async () => { 10 | const { registerSW } = await import('virtual:pwa-register') 11 | registerSW({ immediate: true }) 12 | }) 13 | .catch(() => {}) 14 | } 15 | -------------------------------------------------------------------------------- /src/pages/[...all].vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 60 | 61 | 62 | meta: 63 | layout: empty 64 | 65 | -------------------------------------------------------------------------------- /src/store/newsletter.ts: -------------------------------------------------------------------------------- 1 | import { acceptHMRUpdate, defineStore } from 'pinia' 2 | import { ofetch } from 'ofetch' 3 | 4 | interface newsletterResponse { 5 | id?: number 6 | newsletter?: string 7 | email?: string 8 | error_message?: string 9 | errors?: string[] 10 | success?: boolean 11 | } 12 | 13 | export const useNewsletterStore = defineStore('useNewsletterStore', { 14 | state: () => ({ 15 | response: null as newsletterResponse | null, 16 | }), 17 | 18 | getters: { 19 | getResponse: (state) => state.response, 20 | }, 21 | 22 | actions: { 23 | async subscribe(email: string) { 24 | const grudgetToken = import.meta.env.VITE_GRUDGET_TOKEN || null 25 | const baseUrl = import.meta.env.VITE_GRUDGET_ENDPOINT || null 26 | const newsletter = import.meta.env.VITE_GRUDGET_NEWSLETTER || null 27 | 28 | const response = await ofetch(`${baseUrl}/subscriber/`, { 29 | method: 'POST', 30 | body: { email: email, newsletter: newsletter }, 31 | headers: { 32 | Accept: 'application/json', 33 | 'Content-type': 'application/json', 34 | Authorization: `token ${grudgetToken}`, 35 | }, 36 | }).catch((error) => error.data) 37 | 38 | this.response = response 39 | }, 40 | }, 41 | }) 42 | 43 | if (import.meta.hot) { 44 | import.meta.hot.accept(acceptHMRUpdate(useNewsletterStore, import.meta.hot)) 45 | } 46 | -------------------------------------------------------------------------------- /src/store/reader.ts: -------------------------------------------------------------------------------- 1 | import { acceptHMRUpdate, defineStore } from 'pinia' 2 | 3 | export const useReaderStore = defineStore('reader', { 4 | state: () => ({ 5 | readerMode: false, 6 | availableFontSizes: [ 7 | 'prose-sm', 8 | 'prose-md', 9 | 'prose-lg', 10 | 'prose-xl', 11 | 'prose-2xl', 12 | ], 13 | currentFontSize: 'prose-xl', 14 | }), 15 | 16 | getters: { 17 | isActive: (state) => state.readerMode, 18 | fontSize: (state) => state.currentFontSize, 19 | fontSizes: (state) => state.availableFontSizes, 20 | }, 21 | 22 | actions: { 23 | toggle() { 24 | this.currentFontSize = 'prose-xl' 25 | this.readerMode = !this.readerMode 26 | }, 27 | 28 | setFontSize(size: string) { 29 | this.currentFontSize = size 30 | }, 31 | }, 32 | }) 33 | 34 | if (import.meta.hot) { 35 | import.meta.hot.accept(acceptHMRUpdate(useReaderStore, import.meta.hot)) 36 | } 37 | -------------------------------------------------------------------------------- /src/styles/carbon.css: -------------------------------------------------------------------------------- 1 | #carbonads * { 2 | margin: initial; 3 | padding: initial; 4 | text-align: center; 5 | } 6 | 7 | #carbonads { 8 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 9 | Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', Helvetica, Arial, 10 | sans-serif; 11 | display: inline-block; 12 | font-size: 13px; 13 | max-height: 200px; 14 | } 15 | 16 | #carbonads a, 17 | #carbonads a:hover { 18 | color: #444; 19 | text-decoration: none; 20 | } 21 | 22 | #carbonads > span { 23 | display: grid; 24 | max-width: 200px; 25 | padding: 1.5em; 26 | box-sizing: border-box; 27 | } 28 | 29 | #carbonads img { 30 | margin: auto; 31 | border-radius: 5%; 32 | } 33 | 34 | #carbonads .carbon-wrap { 35 | display: grid; 36 | row-gap: 1em; 37 | height: 220px; 38 | } 39 | #carbonads .carbon-text { 40 | font-size: 1em; 41 | margin-bottom: 5em; 42 | } 43 | 44 | .dark #carbonads .carbon-text { 45 | color: #e2e8f0; 46 | } 47 | 48 | #carbonads .carbon-poweredby { 49 | opacity: 0.5; 50 | font-size: 0.725em; 51 | text-transform: uppercase; 52 | font-weight: 600; 53 | letter-spacing: 0.05ch; 54 | } 55 | 56 | .dark #carbonads .carbon-poweredby { 57 | color: #e2e8f0; 58 | } 59 | -------------------------------------------------------------------------------- /src/styles/fonts.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Lexend'; 3 | font-style: normal; 4 | font-weight: 100 900; 5 | font-display: swap; 6 | src: url(/fonts/lexend.woff2) format('woff2'); 7 | } 8 | @font-face { 9 | font-family: 'Inter'; 10 | font-weight: 100 900; 11 | font-display: block; 12 | font-style: normal; 13 | font-named-instance: 'Regular'; 14 | src: url('/fonts/Inter-roman.var.woff2') format('woff2'); 15 | } 16 | @font-face { 17 | font-family: 'Inter'; 18 | font-weight: 100 900; 19 | font-display: block; 20 | font-style: italic; 21 | font-named-instance: 'Italic'; 22 | src: url('/fonts/Inter-italic.var.woff2') format('woff2'); 23 | } 24 | -------------------------------------------------------------------------------- /src/styles/index.css: -------------------------------------------------------------------------------- 1 | @import './markdown.css'; 2 | @import './fonts.css'; 3 | @import './docsearch.css'; 4 | @import './carbon.css'; 5 | @tailwind base; 6 | @tailwind components; 7 | @tailwind utilities; 8 | -------------------------------------------------------------------------------- /src/styles/markdown.css: -------------------------------------------------------------------------------- 1 | /* https://github.com/antfu/prism-theme-vars */ 2 | @import 'prism-theme-vars/base.css'; 3 | 4 | .prose { 5 | --prism-font-family: 'DM Mono', monospace; 6 | } 7 | 8 | .prose img { 9 | width: 100%; 10 | } 11 | 12 | html .prose { 13 | --prism-foreground: #f8fafc; 14 | --prism-background: #2f2f2f; 15 | --prism-comment: #94a3b8; 16 | --prism-string: #a5e844; 17 | --prism-interpolation: #ff6666; 18 | --prism-literal: #429988; 19 | --prism-keyword: #7bddff; 20 | --prism-operator: #7bddff; 21 | --prism-boolean: #7bddff; 22 | --prism-number: #fd9170; 23 | --prism-variable: #ff6666; 24 | --prism-function: #c792ea; 25 | --prism-deleted: #a14f55; 26 | --prism-class: #ffcb6b; 27 | --prism-builtin: #82aaff; 28 | --prism-property: #80cbc4; 29 | --prism-namespace: #db889a; 30 | --prism-punctuation: #89ddff; 31 | --prism-decorator: #bd8f8f; 32 | --prism-regex: #f2ff00; 33 | --prism-json-property: #6b8b9e; 34 | --prism-line-number: #888888; 35 | --prism-line-number-gutter: #eeeeee; 36 | --prism-line-highlight-background: #444444; 37 | --prism-selection-background: #444444; 38 | --prism-font-size: 1.03em; 39 | --prism-tab-size: 4; 40 | } 41 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import { type ViteSSGContext } from 'vite-ssg' 2 | 3 | // eslint-disable-next-line no-unused-vars 4 | export type UserModule = (ctx: ViteSSGContext) => void 5 | -------------------------------------------------------------------------------- /src/types/index.d.ts: -------------------------------------------------------------------------------- 1 | export {} 2 | 3 | declare global { 4 | // eslint-disable-next-line no-unused-vars 5 | interface Window { 6 | dataLayer: any 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/types/ui.ts: -------------------------------------------------------------------------------- 1 | import { FunctionalComponent } from 'vue' 2 | 3 | type optionsObject = { 4 | [key: string]: string 5 | } 6 | 7 | type colorObject = { 8 | [key: string]: string | undefined 9 | primary?: string 10 | secondary?: string 11 | transparent?: string 12 | danger?: string 13 | black?: string 14 | blue?: string 15 | gray?: string 16 | purple?: string 17 | pink?: string 18 | orange?: string 19 | green?: string 20 | slate?: string 21 | zinc?: string 22 | neutral?: string 23 | stone?: string 24 | amber?: string 25 | yellow?: string 26 | lime?: string 27 | emerald?: string 28 | tal?: string 29 | cyan?: string 30 | sky?: string 31 | indigo?: string 32 | violet?: string 33 | fuchsia?: string 34 | rose?: string 35 | } 36 | 37 | type sizeObject = { 38 | [key: string]: string | undefined 39 | xs?: string 40 | sm: string 41 | md: string 42 | lg?: string 43 | xl?: string 44 | square?: string 45 | } 46 | 47 | type iconObject = { 48 | [key: string]: FunctionalComponent 49 | } 50 | 51 | export { optionsObject, colorObject, sizeObject, iconObject } 52 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | const defaultTheme = require('tailwindcss/defaultTheme') 2 | 3 | /** @type {import('tailwindcss').Config} */ 4 | module.exports = { 5 | content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'], 6 | darkMode: 'class', 7 | theme: { 8 | fontSize: { 9 | xs: ['0.75rem', { lineHeight: '1rem' }], 10 | sm: ['0.875rem', { lineHeight: '1.5rem' }], 11 | base: ['1rem', { lineHeight: '2rem' }], 12 | lg: ['1.125rem', { lineHeight: '1.75rem' }], 13 | xl: ['1.25rem', { lineHeight: '2rem' }], 14 | '2xl': ['1.5rem', { lineHeight: '2.5rem' }], 15 | '3xl': ['2rem', { lineHeight: '2.5rem' }], 16 | '4xl': ['2.5rem', { lineHeight: '3rem' }], 17 | '5xl': ['3rem', { lineHeight: '3.5rem' }], 18 | '6xl': ['3.75rem', { lineHeight: '1' }], 19 | '7xl': ['4.5rem', { lineHeight: '1' }], 20 | '8xl': ['6rem', { lineHeight: '1' }], 21 | '9xl': ['8rem', { lineHeight: '1' }], 22 | }, 23 | extend: { 24 | fontFamily: { 25 | sans: ['Inter', ...defaultTheme.fontFamily.sans], 26 | display: ['Lexend', ...defaultTheme.fontFamily.sans], 27 | }, 28 | maxWidth: { 29 | '8xl': '88rem', 30 | }, 31 | }, 32 | }, 33 | safelist: ['text-slate-400'], 34 | plugins: [require('@tailwindcss/typography')], 35 | } 36 | -------------------------------------------------------------------------------- /tests/basic.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, expect, it } from 'vitest' 2 | 3 | describe('tests', () => { 4 | it('should works', () => { 5 | expect(1 + 1).toEqual(2) 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "module": "ESNext", 5 | "target": "ESNext", 6 | "lib": [ 7 | "DOM", 8 | "ESNext" 9 | ], 10 | "strict": true, 11 | "esModuleInterop": true, 12 | "jsx": "preserve", 13 | "skipLibCheck": true, 14 | "moduleResolution": "node", 15 | "resolveJsonModule": true, 16 | "noUnusedLocals": true, 17 | "strictNullChecks": true, 18 | "allowJs": true, 19 | "forceConsistentCasingInFileNames": true, 20 | "types": [ 21 | "vitest", 22 | "vite/client", 23 | "vue/ref-macros", 24 | "vite-plugin-pages/client", 25 | "vite-plugin-vue-layouts/client", 26 | "vite-plugin-pwa/client", 27 | ], 28 | "paths": { 29 | "~/*": [ 30 | "src/*", 31 | ] 32 | } 33 | }, 34 | "exclude": [ 35 | "dist", 36 | "node_modules", 37 | "postcss.config.js", 38 | "tailwind.config.js", 39 | "coverage", 40 | "cheatsheet", 41 | ], 42 | "typeRoots": [ 43 | "./src/types" 44 | ] 45 | } -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "esnext", 5 | "moduleResolution": "node" 6 | }, 7 | "include": [ 8 | "vite.config.ts" 9 | ] 10 | } --------------------------------------------------------------------------------