Skip to content

Commit

Permalink
Merge pull request #522 from realpython/python-data-types
Browse files Browse the repository at this point in the history
Sample code for the article on basic types
  • Loading branch information
brendaweles committed Apr 28, 2024
2 parents ed5aeeb + 0076c0e commit cd2d65e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python-basic-data-types/README.md
@@ -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
@@ -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
@@ -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}")
2 changes: 2 additions & 0 deletions python-basic-data-types/f_string.py
@@ -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
@@ -0,0 +1 @@
print((42).as_integer_ratio())
7 changes: 7 additions & 0 deletions python-basic-data-types/person.py
@@ -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
@@ -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))

0 comments on commit cd2d65e

Please sign in to comment.