GithubHelp home page GithubHelp logo

wilfredinni / python-cheatsheet Goto Github PK

View Code? Open in Web Editor NEW
4.0K 93.0 1.2K 22.16 MB

All-inclusive Python cheatsheet

Home Page: https://www.pythoncheatsheet.org

License: MIT License

JavaScript 1.34% TypeScript 15.69% HTML 0.83% Vue 69.17% CSS 12.97%
python python-basics python-beginners quickbooks reference cheatsheet python-cheatsheet

python-cheatsheet's People

Contributors

abdussalam02 avatar acumane avatar azanbinzahid avatar ckartchner avatar danielpclin avatar flymemoryrpa avatar gsemet avatar hasnathridoy avatar lairdstreak avatar mat1g3r avatar matteodem avatar michaelbaluja avatar mozarm avatar noraa-july-stoke avatar nugel avatar omii2k01 avatar pms-crypto avatar rawatdev avatar rbuzzell avatar renovate[bot] avatar samithamphk avatar senlog avatar shirinapr avatar sonatrix avatar sztheory avatar thoughtworks-tcaceres avatar vaibhavb02 avatar vishesh-dd4723 avatar wilfredinni avatar yaya9256 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-cheatsheet's Issues

Clarifying wording for 'continue Statements'

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.

Please include "Requests" Library

"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.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
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

  • Check this box to trigger a request for Renovate to run again on this repository

Possible typo

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.

New topic: dataclasses

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

Clasess

Add a new topic to the cheat sheet: Classes

Section "Final code in exception handling" has errors

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 --

String Formatting

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.

wrong result of zip function

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.

Missing parentheses

There are missing parentheses in Path examples, in Linux and Mac. If someone just copy and paste on terminal, it doesn't work.

image

Typo in 'Handling file and directory Paths'

In the first sentence it says:

There are two main modules in Python that deals with path manipulation.

should be:

There are two main modules in Python that deal with path manipulation.

OOP Basics?

Would a section on OOP basics be worthy or too much content for the cheatsheet?

  • Define a Class in Python
  • Instantiate an Object
  • Inherit From Other Classes
  • Calling Methods

Inaccurate information

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

Typo in Python String Formatting

I guess there is a typo in the article. You used %x instead of %d
the %d format specifier is used to convert an int value to a string, while %x helps to format the hexadecimal representation of the integer.

image

.title() method missing from Manipulating strings

.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.

json module

Add a new topic to the cheat sheet: json module

Metaclass

Hi. I thought about adding a new topic "Metaclass".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.