MATH 1MP3 Lecture Notes - Lecture 1: Pycharm, Concatenation, Matlab

295 views3 pages
MATH 1MP3 Week 1
About Python:
Python is a general-purpose programming language. There are also domain-specific scripting languages
like MATLAB and general-purpose compiled languages like Java.
Python works by executing lines of code. These lines are read sequentially. A visual IDE like Spyder or
PyCharm is useful.
Assignment and types Ch. 2
This sets aside memory space for a variable and a set value.
- = is the assignment operator. It is different from ‘equals’
- <variable> = <value>
Convention: Variable names with multiple words are separated by underscores. (Hello_World)
Variable Types
Variables are of different types.
- Integer, floating-point, complex
- Boolean (True or False)
Arithmetic Operators
- Exponentiation (**)
- Negation (-)
- Multiplication/Division (*, /, // = integer division, % = remainder)
- Addition/Subtraction (+, -)
Logical Operators
- Comparison: ==, !=
- Inequalities: >, <, >=, <=,
- Basic logic: and, or not
Strings and String Operations (Ch 4)
Strings are denoted by “”. You can set them to a variable such as text = “hello world”
- “” and ‘’ can both denote strings. I recommend using “”
- Strings can be empty -> “”
- Len(s) returns the length
Concatenation
- Adds two strings together
o “Albert” + “ Einstein- Spaces are also concatenated
o ‘Albert Einstein’’
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

Document Summary

There are also domain-specific scripting languages like matlab and general-purpose compiled languages like java. This sets aside memory space for a variable and a set value. Convention: variable names with multiple words are separated by underscores. (hello_world) Multiplication/division (*, /, // = integer division, % = remainder) You can set them to a variable such as text = hello world . Adds two strings together: albert + einstein - spaces are also concatenated. Negative indices count backwards from the string. Extracting consecutive sets of elements is called slicing. Slicing works on strings, lists\ x[:] x[a:b] x[a:] x[:b] x[a:b:n] # from a to b-1 in steps of n. If you attempt to put a single quote in a string. When python encounters the second quote, it thinks the string has ended when it hasn"t. We can solve this example with double quotations.