Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions python-basic-data-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Basic Data Types in Python: A Quick Exploration

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/).
2 changes: 2 additions & 0 deletions python-basic-data-types/double_single_quote_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
print("I am a string")
# print('I am a string too')
14 changes: 14 additions & 0 deletions python-basic-data-types/escape_seqs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tab
print("a\tb")

# Linefeed
print("a\nb")

# Octal
print("\141")

# Hex
print("\x61")

# Unicode by name
print("\N{rightwards arrow}")
Comment thread
martin-martin marked this conversation as resolved.
2 changes: 2 additions & 0 deletions python-basic-data-types/f_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
income = 1234.1234
print(f"Income: ${income:.2f}")
1 change: 1 addition & 0 deletions python-basic-data-types/integer_ratio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print((42).as_integer_ratio())
7 changes: 7 additions & 0 deletions python-basic-data-types/person.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Person:
def __init__(self, name, age):
self.name = name
self.age = age

def __str__(self):
return f"I'm {self.name}, and I'm {self.age} years old."
15 changes: 15 additions & 0 deletions python-basic-data-types/point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Point:
def __init__(self, x, y):
self.x = x
self.y = y

def __bool__(self):
if self.x == self.y == 0:
return False
return True


origin = Point(0, 0)
print(bool(origin))
point = Point(2, 4)
print(bool(point))