0% found this document useful (0 votes)
5 views3 pages

Python Operators and Data Types Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Python Operators and Data Types Guide

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Operators, Literals & Data Types - Quick

Revision Chart

Relational Operators
Operator Meaning Example Output

== Equal to 5 == 5 True
!= Not equal to 5 != 3 True
> Greater than 7>4 True
< Less than 2<9 True
>= Greater than or equal to 5 >= 5 True
<= Less than or equal to 3 <= 8 True

Logical Operators
Operator Meaning Example Output

and True if both are True 5 > 2 and 7 > 4 True


or True if at least one is True 5 > 10 or 3 < 8 True
not Reverses result not(5 > 2) False

Assignment Operators
Operator Meaning Example Equivalent To

= Assign value x=5 x=5


+= Add and assign x += 3 x=x+3
-= Subtract and assign x -= 2 x=x-2
*= Multiply and assign x *= 4 x=x*4
/= Divide and assign x /= 2 x=x/2
%= Modulus and assign x %= 3 x=x%3
**= Exponentiation and assign x **= 2 x = x ** 2
//= Floor divide and assign x //= 2 x = x // 2

Conditional (Ternary) Operator


Syntax Example Explanation

a if condition else b max_val = x if x > y else y If condition is True → result is a, else → result is b
Literals - Numeric
Type Example

Integer a = 10, b = -25, c = 0o12 (octal), d = 0x1A (hex)


Float pi = 3.14, neg = -0.75
Complex z = 2+3j

Literals - String
Type Example

Single Quotes str1 = 'Hello'


Double Quotes str2 = "Python"
Triple Quotes str3 = '''Multi-line string'''

Literals - Boolean
Type Example Note

Boolean x = True, y = False Internally True=1, False=0

Escape Sequences
Escape Meaning Example → Output

\n New Line "Hello\nWorld" → Hello ■ World


\t Tab Space "Hello\tWorld" → Hello World
\" Double Quote "He said \"Yes\"" → He said "Yes"
\' Single Quote 'It\'s ok' → It's ok
\\ Backslash "C:\\Python" → C:\Python

Python Data Types - Numbers


Type Example

Integer a = 10 (decimal), b = 0o12 (octal), c = 0x1A (hex)


Float pi = 3.14, neg = -2.5
Complex z = 2+3j ([Link]=2.0, [Link]=3.0)

Python Data Types - Boolean


Type Example Note

Boolean x = True, y = False True=1, False=0


Python Data Types - String
Type Example

Single-line name = 'Python'


Multi-line message = '''This is a multi-line string'''

Python Data Types - Collections (Later Chapters)


Type Example

List [1, 2, 3]
Tuple (1, 2, 3)
Set {1, 2, 3}
Dictionary {"name":"Alice", "age":20}

You might also like