You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Jure Šorn 8be850c556 Added condensed and libraries markdown files 7 years ago
CONDENSED.md Added condensed and libraries markdown files 7 years ago
LIBRARIES.md Added condensed and libraries markdown files 7 years ago
README.md Added condensed and libraries markdown files 7 years ago

README.md

Python and Libraries Cheatsheet

Main

if __name__ == '__main__':
    main()

Range

range(<to exclusive>)
range(<from inclusive>, <to exclusive>)
range(<from inclusive>, <to exclusive>, <step size>)  # Negative step for backward

List

<list>[<inclusive from>:<exclusive to>:<step size>]
<list>.extend(<list>)
<list>.sort()
<list>.reverse()
sum(<list>)

Dictionary

.items() .get(, ) .setdefault(, )


Set
---

= set() .add() .update() .union() .intersection() .difference()


Enumerate
---------

for i, in enumerate()




Type
----

type() is int/str/set/list

import numbers isinstance(, numbers.Number)




String
------

str.replace(, , ) .isnumeric()


### Print

print(, , end='', sep='', file=)


### Regex

import re re.sub(, , ) re.search(, )


### Format

'{}'.format()


{:} -> ' ' {:>} -> ' ' {:^} -> ' ' {:} -> '___' {:.} -> '' {:.} -> ' ' {:.f} -> ' 3.14'


### Text Wrap

import textwrap textwrap.wrap(, )



Random
------

import random random.random() random.randint(, ) random.shuffle()


Infinity
--------

float("inf")


Datetime
--------

import datetime now = datetime.datetime.now() now.strftime('%Y%m%d') now.strftime('%Y%m%d%H%M%S')






Inline
------
### For

[i+1 for i in range(10)] [i+1 for i in range(10) if i > 5] [i+j for i in range(10) for j in range(10)]


### Lambda

lambda , : lambda:


Class
-----
### Class

class : def init(self, ): self.a = def repr(self): return str({'a': self.a}) def str(self): return str(self.a)


### Enum
----

import enum class (enum.Enum): =


### Copy

import copy copy.copy(