📚
Learn Python
  • Overview
  • Day 1
  • strings
  • Functions
  • Day 4
  • Day 5
  • Web Development: Flask
    • Installation
      • Virtual Environment
    • Configuration
      • Environment variable in Windows
    • SDLC
  • Python OOPs
    • Python Dunder
    • Page 1
  • Machine Learning
    • Deployment
  • Contributors
Powered by GitBook
On this page
  • integer
  • mathematical operation
  • strings
  • built-in attributes of print function
  • float
  • boolean: True or false
  • if conditions, if a == True, while True (infinite)
  • variable names:
  • type, int, float, bool, string
  • type cast: cast a type (
  • input, adding string to integer
  • eval
  • boolean
  • r = google.com
  • e = request("google.com")
  • Compare strings
  • character encoding, h (23) -> binary
  • ord()
  • in
  • 1 or 0

Was this helpful?

Day 1

Concepts, Code Examples and Task

integer

a = 2 b = 3

mathematical operation

print(a+b, a-b, ab, a/b, a//b, a*b) # sum, sub, mul, div, power (2^3)

a > b a < b

strings

a = "shariq" b = "magistersign"

print(a, b) print(a + b)

firstName = "shariq" lastName = "abcd" empty = " "

print(firstName + "|" +lastName) # string concatenation

built-in attributes of print function

print(firstName, lastName, sep = ":")

float

a = 1.1 b = 1.3 print(a + b)

print( 1 + 1.2 ) print("shariq" + 1)

print("shariq"*2)

boolean: True or false

a = False b = True

if conditions, if a == True, while True (infinite)

response = a > b

print(-3//2, -3/2, 23, 22*3) print(22*3)

variable names:

2numnber = 2 # wrong var r = 4 # wrong

var_1 = 2 # right Var = 3 # right secondName = 2

type, int, float, bool, string

type(secondName)

type cast: cast a type (

e = '2' r = int(e) type(r)

e = 2 r = str(e) type(r)

bool(1) bool(0)

input, adding string to integer

user = input("enter an input")

"shariq" + 1

user = int(input("enter integer value"))

eval

user = eval(input("enter value"))

boolean

user = bool(input("enter something"))

r = google.com

e = request("google.com")

comparison types, > ,<, == (to check), = (assignment)

Compare strings

1 > 1 
2 > 2 
3 == 3 
1.1 == 1.1

"shariq" == "Shariq" "shariq" == "shariq" "shariq" > "Shariq" "a" > 'A'

character encoding, h (23) -> binary

Task: the difference between ascii code and utf character encoding

ord()

ord("a") ord('A')
ord('s') ord("S")
"shariq" > "sHariq" print(ord("a"), ord("b")) print(ord("A"), ord("B"))
"abcd" > "abcD"
chr(3432)

Task:

  1. max number of values in utf vs ascii

  2. which character encoding does your Microsoft word uses

is, in - membership operator

r = 1 f = 1 r is f

in

"q" in "shariq"

or and

"q" in "shariq" # sharik, sharique 1 and 0 or 1

"que" in "shariq" or "k" in "shariq"

1 or 0

False or False and True

PreviousOverviewNextstrings

Last updated 1 year ago

Was this helpful?

2KB
day1.py
Day 1