diff --git a/python-basic-data-types/README.md b/python-basic-data-types/README.md new file mode 100644 index 0000000000..d6488b5ed5 --- /dev/null +++ b/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/). diff --git a/python-basic-data-types/double_single_quote_string.py b/python-basic-data-types/double_single_quote_string.py new file mode 100644 index 0000000000..50f7cf2f3c --- /dev/null +++ b/python-basic-data-types/double_single_quote_string.py @@ -0,0 +1,2 @@ +print("I am a string") +# print('I am a string too') diff --git a/python-basic-data-types/escape_seqs.py b/python-basic-data-types/escape_seqs.py new file mode 100644 index 0000000000..154b8ecc18 --- /dev/null +++ b/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}") diff --git a/python-basic-data-types/f_string.py b/python-basic-data-types/f_string.py new file mode 100644 index 0000000000..4988e9dd6f --- /dev/null +++ b/python-basic-data-types/f_string.py @@ -0,0 +1,2 @@ +income = 1234.1234 +print(f"Income: ${income:.2f}") diff --git a/python-basic-data-types/integer_ratio.py b/python-basic-data-types/integer_ratio.py new file mode 100644 index 0000000000..f9b7bebe5a --- /dev/null +++ b/python-basic-data-types/integer_ratio.py @@ -0,0 +1 @@ +print((42).as_integer_ratio()) diff --git a/python-basic-data-types/person.py b/python-basic-data-types/person.py new file mode 100644 index 0000000000..08bc929a73 --- /dev/null +++ b/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." diff --git a/python-basic-data-types/point.py b/python-basic-data-types/point.py new file mode 100644 index 0000000000..a2fbc96fa1 --- /dev/null +++ b/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))