wilfredinni / python-cheatsheet Goto Github PK
View Code? Open in Web Editor NEWAll-inclusive Python cheatsheet
Home Page: https://www.pythoncheatsheet.org
License: MIT License
All-inclusive Python cheatsheet
Home Page: https://www.pythoncheatsheet.org
License: MIT License
I think there's some ambiguity in the current wording for 'continue Statements'.
Current wording is:
When the program execution reaches a continue statement, the program execution immediately jumps back to the start of the loop.
To me the ambiguity is that it might be interpreted as saying that the loop starts entirely again as though it had not yet been started.
Less ambiguous might be:
When the program execution reaches a continue statement, the program execution skips directly to the start of the next iteration of the loop (if there is one or more remaining), bypassing any other code remaining in the current iteration of the loop.
They are less seen in the wild but really useful to maximize code compatibility
"Requests" is a common topic in technical interviews, where you have to share your screen and retrieve data from a public API. Would be helpful for many to have it on the cheat sheet.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@vue/compiler-dom
, vue
)@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
)package.json
@docsearch/js ^3.6.0
@headlessui/vue ^1.7.19
@vueuse/core ^10.9.0
@vueuse/head ^2.0.0
pinia ^2.1.7
prism-theme-vars ^0.2.4
vue ^3.4.21
vue-gtag ^2.0.1
vue-router ^4.3.0
@tailwindcss/forms ^0.5.7
@tailwindcss/typography ^0.5.12
@types/fs-extra ^11.0.4
@types/markdown-it ^14.0.1
@types/markdown-it-link-attributes ^3.0.5
@types/node ^20.12.7
@types/string 0.0.34
@typescript-eslint/eslint-plugin ^6.21.0
@typescript-eslint/parser ^6.21.0
@vitejs/plugin-vue ^5.0.4
@vue/compiler-dom 3.4.21
@vue/test-utils ^2.4.5
autoprefixer ^10.4.19
eslint ^8.57.0
eslint-config-prettier ^9.1.0
eslint-plugin-vue ^9.24.1
esno ^4.7.0
fs-extra ^11.2.0
happy-dom ^13.10.1
markdown-it ^14.1.0
markdown-it-anchor ^8.6.7
markdown-it-link-attributes ^4.0.1
markdown-it-prism ^2.3.0
ofetch ^1.3.4
postcss ^8.4.38
prettier ^3.2.5
prettier-plugin-tailwindcss ^0.5.13
prismjs ^1.29.0
string ^3.3.3
tailwindcss ^3.4.3
typescript ^5.4.5
unplugin-auto-import ^0.17.5
unplugin-vue-components ^0.26.0
unplugin-vue-markdown ^0.26.1
vite ^5.2.8
vite-plugin-pages ^0.32.1
vite-plugin-pwa ^0.19.8
vite-plugin-vue-layouts ^0.11.0
vite-ssg ^0.23.6
vite-ssg-sitemap ^0.6.1
vitest ^1.5.0
vue-tsc ^2.0.13
The Regular Expressions page contains the following sentence in the "The Caret and Dollar sign characters" section:
The r'\d\$' regular expression string matches strings that end with a numeric character from 0 to 9:
I believe the backslash before the '$' is incorrect. FYI.
Python 3.6+: dataclasses
Python 2.7+: attrs
they are not part of the std (from 3.7, dataclasses are), but really really make the code much more readable
Add a new topic to the cheat sheet: Classes
Example of code in the section has errors. The real output will be different from what is said in listing.
It will be
-- division finished --
2.0
-- division finished --
12.0
Error: Invalid argument: division by zero
-- division finished --
None
instead of
21.0
-- division finished --
3.5
-- division finished --
Error: Invalid argument: division by zero
-- division finished --
None
-- division finished --
Add a new topic to the cheat sheet: pathlib module.
This is awesome :) I don't see any mention of String Formatting though. I think it'd be useful to have this right by the String Concatenation since it should preferred over chaining concatenations for more complex strings.
key = "foo"
value = "bar"
baz = "{}: {}".format(key, value)
baz = "First value: {0}, Second value: {1}".format(key, value)
baz = "key: {key}, value: {value}".format(key=key, value=value)
The .format
method should be used over the %
formatting syntax for compatibility with Python 3. A notable exception is logging. In the Logging
section you have the following line:
logging.debug('Start of factorial(%s)' % (n))
This is a total micro-optimization but doing this causes the string formatting to occur even if the log level isn't debug. You can skip the formatting and pass the variables as extra arguments and the logging library will automatically format the message before printing:
logging.debug('Start of factorial(%s)', n)
However in that case only the %
formatting syntax is supported in Python 2.
There is mistake in zip's result, last output of func should be 'Elizabeth is 44 years old', not 'Alice is 44 years old', logic does not change, but eyes mazolite.
I've been reading through the guide and was a little confused by the dedent
clarification (https://github.com/wilfredinni/python-cheatsheet#multiline-strings-with-triple-quotes). Just thought one or two more lines here may be helpful about dedent function and why the .strip() method was used on the print function.
There are missing parentheses in Path examples, in Linux and Mac. If someone just copy and paste on terminal, it doesn't work.
In the first sentence it says:
should be:
Would a section on OOP basics be worthy or too much content for the cheatsheet?
The Python cheatsheet currently contains the following inaccurate information in the Boolean Evaluation section:
These statements are equivalent:
>>> if a is True:
>>> pass
>>> if a is not False:
>>> pass
>>> if a:
>>> pass
And these as well:
>>> if a is False:
>>> pass
>>> if a is not True:
>>> pass
>>> if not a:
>>> pass
Unfortunately, the above is incorrect. Consider the following:
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
>>> a = 4
>>> a is True
False
>>> a is not False
True
>>> if a:
... print('a evaluates to True even though it is not True')
...
a evaluates to True even though it is not True
>>> b = 0
>>> b is False
False
>>> b is not True
True
>>> if b:
... print('b evaluates to True')
... else:
... print('b evaluates to False even though it is not False')
...
b evaluates to False even though it is not False
.title() method is missing from the Maniupulating Strings section of the cheatsheet.
Current situation:
Title is only referenced by way of the istitle() method in the IsX section. I.e. no reference to string.title() method.
Contrast this with methods for upper and lower, both of which have sections for .isupper()/islower() and .upper()/.lower().
Expected behaviour:
string.title() explicitly explained in the Manipulating Strings section of the cheatsheet.
E.g. Include string.title() in the same box as upper() and lower() methods. In which case it would also probably make sense to pull istitle() out of the IsX box and instead include it alongside isupper() and islower() for consistency.
on this page: https://www.pythoncheatsheet.org/cheatsheet/virtual-environments#anaconda
the hyperlink is pointing to Pipenv website (https://pipenv.pypa.io/en/latest/)
Add a new topic to the cheat sheet: json module
furniture[-1] = bed
furniture
Hi. I thought about adding a new topic "Metaclass".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.