100% found this document useful (1 vote)
139 views17 pages

Elzeroweb Part - 1

The level of the residential cell: It is served by shops that sell some basic consumer goods for some of the requirements of daily living

Uploaded by

tik took
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
139 views17 pages

Elzeroweb Part - 1

The level of the residential cell: It is served by shops that sell some basic consumer goods for some of the requirements of daily living

Uploaded by

tik took
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

# -----------------------------

# -- Tuple --

# -----------

# [1] Tuple Items Are Enclosed in Parentheses

# [2] You Can Remove The Parentheses If You Want

# [3] Tuple Are Ordered, To Use Index To Access Item

# [4] Tuple Are Immutable => You Cant Add or Delete

# [5] Tuple Items Is Not Unique

# [6] Tuple Can Have Different Data Types

# [7] Operators Used in Strings and Lists Available In Tuples

# -----------------------------

# Tuple Syntax & Type Test

myAwesomeTupleOne = ("Osama", "Ahmed")

myAwesomeTupleTwo = "Osama", "Ahmed"

print(myAwesomeTupleOne)

print(myAwesomeTupleTwo)

print(type(myAwesomeTupleOne))

print(type(myAwesomeTupleTwo))

# Tuple Indexing

myAwesomeTupleThree = (1, 2, 3, 4, 5)

print(myAwesomeTupleThree[0])

print(myAwesomeTupleThree[-1])

print(myAwesomeTupleThree[-3])

# Tuple Assign Values


myAwesomeTupleFour = (1, 2, 3, 4, 5)

# myAwesomeTupleFour[2] = "Three"

# print(myAwesomeTupleFour) # 'tuple' object does not support item assignment

# Tuple Data

myAwesomeTupleFive = ("Osama", "Osama", 1, 2, 3, 100.5, True)

print(myAwesomeTupleFive[1])

print(myAwesomeTupleFive[-1])

# -----------

# -- Tuple --

# -----------

# Tuple With One Element

myTuple1 = ("Osama",)

myTuple2 = "Osama",

print(myTuple1)

print(myTuple2)

print(type(myTuple1))

print(type(myTuple2))

print(len(myTuple1))

print(len(myTuple2))

# Tuple Concatenation

a = (1, 2, 3, 4)
b = (5, 6)

c=a+b

d = a + ("A", "B", True) + b

print(c)

print(d)

# Tuple, List, String Repeat (*)

myString = "Osama"

myList = [1, 2]

myTuple = ("A", "B")

print(myString * 6)

print(myList * 6)

print(myTuple * 6)

# Methods => count()

a = (1, 3, 7, 8, 2, 6, 5, 8)

print(a.count(8))

# Methods => index()

b = (1, 3, 7, 8, 2, 6, 5)

# print("The Position of Index Is: " + b.index(7)) # Error

print("The Position of Index Is: {:d}".format(b.index(7)))

print(f"The Position of Index Is: {b.index(7)}")

# Tuple Destruct
a = ("A", "B", 4, "C")

x, y, _, z = a

print(x)

print(y)

print(z)

# -----------------------------

# -- Set --

# ---------

# [1] Set Items Are Enclosed in Curly Braces

# [2] Set Items Are Not Ordered And Not Indexed

# [3] Set Indexing and Slicing Cant Be Done

# [4] Set Has Only Immutable Data Types (Numbers, Strings, Tuples) List and Dict Are Not

# [5] Set Items Is Unique

# -----------------------------

# Not Ordered And Not Indexed

mySetOne = {"Osama", "Ahmed", 100}

print(mySetOne)

# print(mySetOne[0])

# Slicing Cant Be Done

mySetTwo = {1, 2, 3, 4, 5, 6}

# print(mySetTwo[0:3])

# Has Only Immutable Data Types

# mySetThree = {"Osama", 100, 100.5, True, [1, 2, 3]} # unhashable type: 'list'

mySetThree = {"Osama", 100, 100.5, True, (1, 2, 3)}


print(mySetThree)

# Items Is Unique

mySetFour = {1, 2, "Osama", "One", "Osama", 1}

print(mySetFour)

# -----------------

# -- Set Methods --

# -----------------

# clear()

a = {1, 2, 3}

a.clear()

print(a)

# union()

b = {"One", "Two", "Three"}

c = {"1", "2", "3"}

x = {"Zero", "Cool"}

print(b | c)

print(b.union(c, x))

# add()

d = {1, 2, 3, 4}

d.add(5)
d.add(6)

print(d)

# copy()

e = {1, 2, 3, 4}

f = e.copy()

print(e)

print(f)

e.add(6)

print(e)

print(f)

# remove()

g = {1, 2, 3, 4}

g.remove(1)

# g.remove(7)

print(g)

# discard()

h = {1, 2, 3, 4}

h.discard(1)

h.discard(7)

print(h)

# pop()
i = {"A", True, 1, 2, 3, 4, 5}

print(i.pop())

# update()

j = {1, 2, 3}

k = {1, "A", "B", 2}

j.update(['Html', "Css"])

j.update(k)

print(j)

# -----------------

# -- Set Methods --

# -----------------

# difference()

a = {1, 2, 3, 4}

b = {1, 2, 3, "Osama", "Ahmed"}

print(a)

print(a.difference(b)) # a - b

print(a)

print("=" * 40) # Separator

# difference_update()

c = {1, 2, 3, 4}

d = {1, 2, "Osama", "Ahmed"}

print(c)

c.difference_update(d) # c - d
print(c)

print("=" * 40) # Separator

# intersection()

e = {1, 2, 3, 4, "X", "Osama"}

f = {"Osama", "X", 2}

print(e)

print(e.intersection(f)) # e & f

print(e)

print("=" * 40) # Separator

# intersection_update()

g = {1, 2, 3, 4, "X", "Osama"}

h = {"Osama", "X", 2}

print(g)

g.intersection_update(h) # g & h

print(g)

print("=" * 40) # Separator

# symmetric_difference()

i = {1, 2, 3, 4, 5, "X"}

j = {"Osama", "Zero", 1, 2, 4, "X"}

print(i)

print(i.symmetric_difference(j)) # i ^ j

print(i)
print("=" * 40) # Separator

# symmetric_difference_update()

k = {1, 2, 3, 4, 5, "X"}

l = {"Osama", "Zero", 1, 2, 4, "X"}

print(k)

k.symmetric_difference_update(l) # k ^ l

print(k)

# -----------------

# -- Set Methods --

# -----------------

# issuperset()

a = {1, 2, 3, 4}

b = {1, 2, 3}

c = {1, 2, 3, 4, 5}

print(a.issuperset(b)) # True

print(a.issuperset(c)) # False

print("=" * 50)

# issubset()

d = {1, 2, 3, 4}

e = {1, 2, 3}

f = {1, 2, 3, 4, 5}
print(d.issubset(e)) # False

print(d.issubset(f)) # True

print("=" * 50)

# isdisjoint()

g = {1, 2, 3, 4}

h = {1, 2, 3}

i = {10, 11, 12}

print(g.isdisjoint(h)) # False

print(g.isdisjoint(i)) # True

# ---------------------------

# -- Dictionary --

# ----------------

# [1] Dict Items Are Enclosed in Curly Braces

# [2] Dict Items Are Contains Key : Value

# [3] Dict Key Need To Be Immutable => (Number, String, Tuple) List Not Allowed

# [4] Dict Value Can Have Any Data Types

# [5] Dict Key Need To Be Unique

# [6] Dict Is Not Ordered You Access Its Element With Key

# ----------------------------

# Dictionary

user = {

"name": "Osama",

"age": 36,

"country": "Egypt",

"skills": ["Html", "Css", "JS"],


"rating": 10.5

print(user)

print(user['country'])

print(user.get("country"))

print(user.keys())

print(user.values())

# Two-Dimensional Dictionary

languages = {

"One": {

"name": "Html",

"progress": "80%"

},

"Two": {

"name": "Css",

"progress": "90%"

},

"Three": {

"name": "Js",

"progress": "90%"

print(languages)

print(languages['One'])

print(languages['Three']['name'])

# Dictionary Length
print(len(languages))

print(len(languages["Two"]))

# Create Dictionary From Variables

frameworkOne = {

"name": "Vuejs",

"progress": "80%"

frameworkTwo = {

"name": "ReactJs",

"progress": "80%"

frameworkThree = {

"name": "Angular",

"progress": "80%"

allFramework = {

"one": frameworkOne,

"two": frameworkTwo,

"three": frameworkThree

print(allFramework)

# ------------------------

# -- Dictionary Methods --

# ------------------------
# clear()

user = {

"name": "Osama"

print(user)

user.clear()

print(user)

print("=" * 50)

# update()

member = {

"name": "Osama"

print(member)

member["age"] = 36

print(member)

member.update({"country": "Egypt"})

print(member)

print("=" * 50)

# copy()

main = {

"name": "Osama"

b = main.copy()
print(b)

main.update({"skills": "Fighting"})

print(main)

print(b)

# keys() + values()

print(main.keys())

print(main.values())

# ------------------------

# -- Dictionary Methods --

# ------------------------

# setdefault()

user = {

"name": "Osama"

print(user)

print(user.setdefault("age", 36))

print(user)

print("=" * 40)

# popitem()

member = {

"name": "Osama",

"skill": "PS4"

print(member)
member.update({"age": 36})

print(member.popitem())

print("=" * 40)

# items()

view = {

"name": "Osama",

"skill": "XBox"

allItems = view.items()

print(view)

view["age"] = 36

print(allItems)

print("=" * 40)

# fromkeys()

a = ('MyKeyOne', 'MyKeyTwo', 'MyKeyThree')

b = "X"

print(dict.fromkeys(a, b))

# -------------

# -- Boolean --

# -------------

# [1] In Programming You Need to Known Your If Your Code Output is True Or False

# [2] Boolean Values Are The Two Constant Objects False + True.

# ---------------------------------------------------------------
name = " "

print(name.isspace())

print("=" * 50)

print(100 > 200)

print(100 > 100)

print(100 > 90)

print("=" * 50)

# True Values

print(bool("Osama"))

print(bool(100))

print(bool(100.95))

print(bool(True))

print(bool([1, 2, 3, 4, 5]))

print("=" * 50)

# False Values

print(bool(0))

print(bool(""))

print(bool(''))

print(bool([]))

print(bool(False))

print(bool(()))

print(bool({}))

print(bool(None))
# -----------------------

# -- Boolean Operators --

# -----------------------

# and

# or

# not

# -----------------------

age = 36

country = "Egypt"

rank = 10

print(age > 16 and country == "Egypt" and rank > 0) # True

print(age > 16 and country == "KSA" and rank > 0) # False

print(age > 40 or country == "KSA" or rank > 20) # False

print(age > 40 or country == "Egypt" or rank > 20) # True

print(age > 16) # True

print(not age > 16) # Not True = False

You might also like