Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
68 views

Python: Concatenating Strings

Whitespaces matter in Python code as they determine if an operation is multiplication or exponentiation. Strings can be manipulated using methods like .lower(), .upper(), and concatenation. Dot notation is used to call string methods but not general functions like len() and str(). Lists can be iterated over with for loops and allow indexing, insertion, and removal of elements. Dictionaries map keys to values and allow adding, accessing, and removing key-value pairs. Control flow includes if/elif/else statements and for/else loops. Functions and modules help organize code.

Uploaded by

Dhruv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views

Python: Concatenating Strings

Whitespaces matter in Python code as they determine if an operation is multiplication or exponentiation. Strings can be manipulated using methods like .lower(), .upper(), and concatenation. Dot notation is used to call string methods but not general functions like len() and str(). Lists can be iterated over with for loops and allow indexing, insertion, and removal of elements. Dictionaries map keys to values and allow adding, accessing, and removing key-value pairs. Control flow includes if/elif/else statements and for/else loops. Functions and modules help organize code.

Uploaded by

Dhruv
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Python

Whitespaces matter
E.g.
Product = 3 ** 3 (Power)
Product = 3 * 3 (Multiplication)

When printing a string but an apostrophe is present, python stops the string there, thus

String = “There isn\’t blab la”

print {variable name}

print len(variable name) = gives length of string

print variablename.lower() = uncapitalizes string

print variablename.upper() = capitalises string

print str(variablename) = sets a non string into a string

Dot Notation
Only used for string variables, however, functions such as len and str don’t need it as they can deal
with other data types

print "Spam " + "and " + "eggs" Concatenating strings

print "The value of pi is around " + str(3.14)

String Formatting
Date and Time

Control Flow and Data Input

And Or Not

not True = False

If statements and stuff

Elseif = elif in python

Functions

def functioname(argument):
import math

importing only a certain function from a module

Import these way in order not to have to type math.sqrt all the time. However, it is better to have
math.sqrt as sqrt may be a function name of your own coding.

max(), min(), abs()

type() – returns the type of the data


Lists

Listname = [“blablabal", something]

Lists don’t have a fixed length

include index of item after the last item u want

Finding index then inserting a string into


the list

For Loops
appending numbers into
another list then sorting it

key1 points to 1 and so on

Appending into a
dictionary

Deleting a key from a dictionary

Removing from a list


For loop to print dictionary
Lists in Lists
Add zip to include two lists

For-else

Remove the break to initialise the else statement!

Checking int:

You might also like