Skip to content

Commit cd2d65e

Browse files
authored
Merge pull request #522 from realpython/python-data-types
Sample code for the article on basic types
2 parents ed5aeeb + 0076c0e commit cd2d65e

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Tab
2+
print("a\tb")
3+
4+
# Linefeed
5+
print("a\nb")
6+
7+
# Octal
8+
print("\141")
9+
10+
# Hex
11+
print("\x61")
12+
13+
# Unicode by name
14+
print("\N{rightwards arrow}")

python-basic-data-types/f_string.py

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+
print(bool(origin))
14+
point = Point(2, 4)
15+
print(bool(point))

0 commit comments

Comments
 (0)