CP104 Lecture Notes - Lecture 1: Type Conversion, Decimal Mark, Operand

59 views5 pages
School
Course
Professor
Sept 18 2017
Week 3 notes
Chapter 2 topic three: variables
- Accessible learning centre
- Variable and constant are the same but constants don’t change
- Operator
- Reserved words: keywords used by python
- String: group of characters
- String Literals: single double and triple quotes
- opening/closing quotes must match
- “”” or ‘’’ triple quotations for multiple lines
- Nesting quotes ---- ‘how’s’ ----use different quotation
- Starting a variable w a digit is not valid (e.g 2ab=)
- Starting a variable w an underscore IS valid ( _abc)
- But prefers it to be in the middle
- /n= new line
BASIC DATA TYPES
-Integer (int): whole number ex. -3, 4
-Float (float): with a decimal point ex. -3.21
-boolean( bool) ex. True or false
-String (str)----ex. ‘Python’ , “CP104”
- Dont let everything float too much memory wasted
- miles= 1000.0 ←-----# a floating point
- 100----> whole #
- To find out type ---> print( type(miles))
- (
- Byte(1),
- ‘Hello’ +’ +
Dynamic
- TypeError: must be str, not int ---> ‘CP104’+2
Unlock document

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

Already have an account? Log in
Sept 18 2017
- Fix: ask about the type. type()
- Fix: data type conversion
Data size in memory in general programming: not completely true in python
Operators
- + addition
- - sub
- % Modulus ----> divides left hand by right hand operand and returns remainder ex.
b%a=0
- ** Exponent
- // Floor division- rounds number: floor division rounds down.
Ex. -11/4
> -3.66
-11//4
> -4
Never Divide by zero --------> run time error computer want to run
% Module operator: 34%10=4 since 34 divided by 10 is three, with a remainder of 4
Operator precedence examples
1. Parenthesis is always respected ( )
2. Expontation: **
3. Multiplication, division, and rem
Function: input( )
-Input from user
-input() function returns a string
-E.g l
Unlock document

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

Already have an account? Log in
hayjayshay and 38575 others unlocked
CP104 Full Course Notes
2
CP104 Full Course Notes
Verified Note
2 documents

Document Summary

Variable and constant are the same but constants don"t change. String literals: single double and triple quotes. Nesting quotes ---- how"s" ----use different quotation. Starting a variable w a digit is not valid (e. g 2ab=) Starting a variable w an underscore is valid ( _abc) But prefers it to be in the middle opening/closing quotes must match. Or "" triple quotations for multiple lines. Python" , cp104 miles= 1000. 0 -----# a floating point. Dont let everything float too much memory wasted. Typeerror: must be str, not int ---> cp104"+2. Data size in memory in general programming: not completely true in python. % modulus ----> divides left hand by right hand operand and returns remainder ex. b%a=0. // floor division- rounds number: floor division rounds down. Never divide by zero --------> run time error computer want to run. % module operator: 34%10=4 since 34 divided by 10 is three, with a remainder of 4.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents