-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvariables-types.py
More file actions
112 lines (74 loc) · 2.12 KB
/
variables-types.py
File metadata and controls
112 lines (74 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'''
WIFI PASSWORD : kopikuenak
SSID : THE BROS
'''
'''
NUMBER
=====================
Python supports two types of numbers - integers and floating point numbers.
'''
# # integer
# myint = 7
# print(myint)
# print(type(myint)) # check the type of variable myint
# floating point
# myfloat = 8.0
# print(myfloat)
# myfloat = float(7) # cast integer of 7 become floating poin 0f 7
# print(myfloat)
# print(type(myfloat))
# new_integer_to_float = int(myfloat)
'''
STRINGS
====================
Strings are defined either with a single quote or a double quotes.
'''
# mystring = 'i can'
# mystring = "hello i can't"
# mystring = 'Hello'
# print(mystring)
# mystring = "World"
# print(mystring)
# print(type(mystring))
'''
The difference between the two is that using double quotes makes it easy to include apostrophes (whereas these would terminate the string if using single quotes)
'''
# mystring = "Don't worry about apostrophes"
# print(mystring)
'''
Simple operators can be executed on numbers and strings:
'''
# one = 1
# two = 2
# three = one + two
# print(three)
# hello = "hello"
# world = "world"
# helloworld = hello + " " + world
# print(helloworld)
'''
Assignments can be done on more than one variable "simultaneously" on the same line like this
'''
# a, b = 3, 4
# print(a,b)
'''
Mixing operators between numbers and strings is not supported:
'''
# one = 1
# two = 2
# hello = "hello"
# print(one + two + hello)
'''
The target of this exercise is to create a string, an integer, and a floating point number. The string should be named mystring and should contain the word "hello". The floating point number should be named myfloat and should contain the number 10.0, and the integer should be named myint and should contain the number 20.
'''
# The isinstance() function returns True if the specified object is of the specified type, otherwise False.
mystring = "hello"
myfloat = 10.0
myint = 20
# testing code
if mystring == "hello":
print("String: %s" % mystring)
if isinstance(myfloat, float) and myfloat == 10.0:
print("Float: %f" % myfloat)
if isinstance(myint, int) and myint == 20:
print("Integer: %d" % myint)