Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
smhuda
GitHub Repository: smhuda/python-pcep-notes
Path: blob/main/Module 1 & 2.ipynb
77 views
Kernel: Python 3

Elements of a Programming Language:

  • Alphabet

  • Dictionary

  • Syntax

  • Semantics

Literals/Types:

  • Boolean (True, False)

  • Integer (1, 2, 3, 4, 5)

  • Float (1.0, 3.14, 9.67)

  • String ("This is a string too",'This is also a string')

  • Scientific notation (1e10)

Comments

Single line (#)
Multiple Lines (""" """)
""" This is a comment """

Help Command

dir(print)
help(print)

print('a','b','c', sep='*')
a*b*c
print('a','b','c', end='\t')
a b c

Input Command Function and its Input Types

help(input)

String Input

a = input("Input Something Please:\t") print(type(a))
Input Something Please: This is a test <class 'str'>

Integer Input

numberOfApples = input("Please enter number of Apples required:\t") numberOfApples = int(numberOfApples) print(type(numberOfApples))
Please enter number of Apples required: 10 <class 'int'>

Numerical Types:

  • Binary -> 0b1101

  • Octal -> 0o12354

  • Decimal -> 1212

  • Hexadecimal -> 0x1ae

# Binary print(101112)
101112
# Octal print(0b101)
5
# Decimal print(0o33)
27
# Hexadecimal print(0xFFEE)
65518

Numeric Operations Types:

# Exponent ** print(2**2)
4
# Multiplication * print(2*3)
6
# Division / print(6/3)
2.0
# Divison with Remainder Rounded Off print(2%3)
2
# Integer Divison Operator print(4//4)
1
# Addition print(2+3)
5
# Subtraction print(3-6)
-3
# Print hyphen strings with by multiplication print('-'*3)
---

Using Strings with Operators

print("Loving" + "Dublin")
LovingDublin
print("Pwned"*5)
PwnedPwnedPwnedPwnedPwned
loveStars = '*' * 25 print(loveStars)
*************************

Assginments and Shortcuts:

a = 1 a **= 5 print (a)
1