Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6c8ab96

Browse files
authored
Create les3_declaring_variables.py
In Python, variables are created when you assign a value to it. You can convert from one type to another with the int(), float(), and complex() methods.
1 parent 124ebd0 commit 6c8ab96

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

‎les3_declaring_variables.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#In Python, variables are created when you assign a value to it:
2+
x = 5 #integer
3+
y = "Hi!" #string
4+
z=5.1 #float
5+
zz = 1j # complex
6+
bl=False #boolean
7+
print(bl)
8+
#False
9+
print(x)
10+
#5
11+
print(y)
12+
#Hi!
13+
print(z)
14+
#5.1
15+
print(zz)
16+
#1j
17+
print(type(bl))
18+
print(type(x))
19+
print(type(y))
20+
print(type(z))
21+
print(type(zz))
22+
#<class 'bool'>
23+
#<class 'int'>
24+
#<class 'str'>
25+
#<class 'float'>
26+
#<class 'complex'>
27+
#You can convert from one type to another with the int(), float(), and complex() methods
28+
x = 1 # int
29+
y = 2.8 # float
30+
z = 1j # complex
31+
32+
#convert from int to float:
33+
a = float(x)
34+
35+
#convert from float to int:
36+
b = int(y)
37+
38+
#convert from int to complex:
39+
c = complex(x)
40+
41+
print(a)
42+
print(b)
43+
print(c)
44+
45+
print(type(a))
46+
print(type(b))
47+
print(type(c))
48+
49+
#1.0
50+
#2
51+
#(1+0j)
52+
#<class 'float'>
53+
#<class 'int'>
54+
#<class 'complex'>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /