Skip to content

Commit 9940d4c

Browse files
committed
Sample code for the article on basic types
1 parent e1deb5b commit 9940d4c

7 files changed

Lines changed: 34 additions & 0 deletions

File tree

python-basic-data-types/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Basic Data Types in Python: A Quick Exploration
2+
3+
This folder provides the code examples for the Real Python tutorial [Basic Data Types in Python: A Quick Exploration](https://realpython.com/python-data-types/).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
print("I am a string")
2+
# print('I am a string too')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
print("a\tb")
2+
print("a\nb")
3+
print("a\141\x61")
4+
print("\N{rightwards arrow}")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
income = 1234.1234
2+
print(f"Income: ${income:.2f}")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print((42).as_integer_ratio())

python-basic-data-types/person.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Person:
2+
def __init__(self, name, age):
3+
self.name = name
4+
self.age = age
5+
6+
def __str__(self):
7+
return f"I'm {self.name}, and I'm {self.age} years old."

python-basic-data-types/point.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Point:
2+
def __init__(self, x, y):
3+
self.x = x
4+
self.y = y
5+
6+
def __bool__(self):
7+
if self.x == self.y == 0:
8+
return False
9+
return True
10+
11+
12+
origin = Point(0, 0)
13+
bool(origin)
14+
point = Point(2, 4)
15+
bool(point)

0 commit comments

Comments
 (0)