100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary Final cheat-sheet

Rating
-
Sold
-
Pages
3
Uploaded on
17-07-2024
Written in
2023/2024

This document contains

Institution
Course








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
July 17, 2024
File latest updated on
July 17, 2024
Number of pages
3
Written in
2023/2024
Type
Summary

Subjects

Content preview

Indexing and range (starting from 0 by default)
○ [start (inclusive) : end (exclusive) : stepsize (optional)] = [0, 1, 2, 3] = [-4, -3, -2, -1]. Tip: end - start is the number of elements returned.
○ Range(start (inclusive), stop (exclusive), stepsize). Range(3): 0, 1, 2. The start, stop and step parameters work the same as in list slicing.
○ Set function is used to create a set, particularly useful for removing duplicates from a list or character returns as { }. There is no order.
○ 1: 8: 3 is going to give us: 1, 4 and 7!


Scope (local and global names)
○ Global variables are defined outside functions and are accessible everywhere, but a local variable with the same name inside a function take
precedence (dominates). If a variable isn’t found locally, only then Python looks in the global scope. The global keyword allows modifying
global variables within functions.


String methods (immutable, all of these methods are non-mutating string methods)
○ Escape characters can also be used to include quotes or specific characters: \\ = \, \’ = ‘, \” = “, \n = go to the next line, \t = insert a tab.
○ The individual character(s) of a string can be accessed directly using zero based indexing just like with lists.
○ str.index(value, start, end) – returns the index of the first occurrence of the specified value within the slice (works with strings too)
○ len(x) – returns the number of elements in a list or the number of characters in a string, including spaces, punctuation and other characters.
○ sorted(x) – returns a new list containing all items from x in ascending order. When reverse = True it returns a new list containing all items
from x in descending order. Sorted( ) does not change the original list itself. Works with strings too.
○ str.capitalize( ) – returns a copy of the string with only the first character capitalized and the rest lowercase. It doesn’t change the string, but
returns a new string. You must give that new string a name else you cannot use it in the print statement.
○ str.upper( ) – returns a copy of the string with all alphabetic characters converted to uppercase, leaving the original string unchanged.
○ str.lower( ) – returns a copy of all the characters of the string converted to lowercase.
○ str.isupper( ) – returns True if all characters in the string are uppercase, otherwise it returns False, str.islower( ) it is vice versa.
R162,22
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
EBEdocuments
4,5
(2)

Document also available in package deal

Get to know the seller

Seller avatar
EBEdocuments Universiteit van Amsterdam
Follow You need to be logged in order to follow users or courses
Sold
7
Member since
5 year
Number of followers
5
Documents
20
Last sold
7 months ago

4,5

2 reviews

5
1
4
1
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions