Intermediate Python.pdf

python-cheat-sheet-intermediate.pdf
Preview of Intermediate Python
🔗 Source: s3.amazonaws.com
📊 Size: 64 KB
📄 Pages: 1 page
⬇️ Downloads: 313

Summary

- l.pop(3) removes and returns the fourth item
- l.remove(x) removes the first item equal to x
- l.reverse() reverses the order
- l[1::2] returns every second item
- l[-5:] returns the last 5 items

STRINGS:
- s.lower() returns lowercase
- s.title() capitalizes the first letter of each word
- "23".zfill(4) left-fills with 0's to length 4
- s.splitlines() splits on newline characters
- s[:5] returns the first 5 characters
- "fri" + "end" returns "friend"
- "end" in s checks for substring

RANGE:
- range(5) returns a sequence from 0 to 4
- range(2000,2018) returns a sequence from 2000 to 2017
- range(0,11,2) returns a sequence from 0 to 10, incrementing by 2
- range(0,-10,-1) returns a sequence from 0 to -9
- list(range(5)) returns a list from 0 to 4

DICTIONARIES:
- max(d, key=d.get) returns the key with the largest value
- min(d, key=d.get) returns the key with the smallest value

SETS:
- myset = set(l) returns a set with unique values from l
- len(my
set) returns the number of unique values
- a in myset checks for value existence

REGULAR EXPRESSIONS:
- re.search("abc",s) returns a match object if "abc" is found
- re.sub("abc","xyz",s) replaces "abc" with "xyz"

LIST COMPREHENSION:
- [i 2 for i in range(10)] returns squares of values from 0 to 9
- [s.lower() for s in l
strings] applies .lower() to each item
- [i for i in lfloats if i < 0.5] returns items less than 0.5

FUNCTIONS FOR LOOPING:
- for i, value in enumerate(l) iterates over index and value
- for one, two in zip(l
one,ltwo) iterates over two lists
- while x < 10 runs code until x is no longer less than 10

DATETIME:
- import datetime as dt imports the datetime module
- now = dt.datetime.now() gets the current time
- wks4 = dt.datetime.timedelta(weeks=4) represents a 4-week timespan
- now - wks4 returns the time 4 weeks prior
- newyear
2020 = dt.datetime(year=2020, month=12, day=31) represents December 31, 2020
- newyear2020.strftime("%A, %b %d, %Y") formats the datetime
- dt.datetime.strptime('Dec 31, 2020',"%b %d, %Y") parses a datetime string

RANDOM:
- import random imports the random module
- random.random() returns a random float between 0.0 and 1.0
- random.randint(0,10) returns a random integer between 0 and 10
- random.choice(l) returns a random item from the list

COUNTER:
- from collections import Counter imports the Counter class
- c = Counter(l) counts unique items
- c.most
common(3) returns the 3 most common items

TRY/EXCEPT:
- try/except blocks catch and handle errors
- lints = [1, 2, 3, "", 5] demonstrates error handling with missing values
- l
floats = [] and the for loop convert values to float, handling ValueError

Description

- l.pop(3) removes and returns the fourth item
- l.remove(x) removes the first item equal to x
- l.reverse() reverses the order
- l[1::2] returns every...

Technical Information

  • File Format: PDF
  • File Size: 64 KB
  • Pages: 1
  • Language: EN
  • Total Downloads: 313
  • Last Updated: 4 hours ago

Document Overview

This PDF document about Intermediate Python provides comprehensive information and guidance. Whether you're a beginner or advanced user, this resource offers valuable insights into Intermediate Python.

Related Topics

If you're interested in Intermediate Python, you might also want to explore:

Download Intermediate Python eBooks for free and learn more about Intermediate Python. These books contain exercises and tutorials to improve your practical skills, at all levels!

Not satisfied with this document? We have related documents to Intermediate Python, try searching with similar keywords: Beginning Python Using Python 2 6 And Python 3 1, PDF Crash Python Programming Course Learn Python , PDF Python For Everybody Exploring Data In Python 3, 30 Days Of Python Unlock Your Python Potential, Black Hat Python Python Programming For Hackers An, Gray Hat Python Python Programming For Hackers And, Learn Python In One Day And Learn It Well Python F, Modern Python LiveLessons Big Ideas And Little Code In Python

You can download PDF versions of the user's guide, manuals and ebooks about Intermediate Python, you can also find and download for free A free online manual (notices) with beginner and intermediate, Downloads Documentation, You can download PDF files (or DOC and PPT) about Intermediate Python for free, but please respect copyrighted ebooks.