-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sample.py
110 lines (87 loc) · 2.41 KB
/
test_sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""This is a sample code to test regex statements from python3.yaml syntax file
for Micro text editor, and customize colorschemes suited for the user.
Currently using an extended version or darcula.micro renamed pyrcula.micro"""
import time
from sys import exit as ex
from typing import Any
from collections.abc import Callable
# Variable assignment
SLOT = 5
a_word = "Hi"
# Multi-assignment
one, two, three = [1, 2, 3]
# Type Hint
link: str = "https://google.com"
five: int = 5
n_list: list[int] = [4, 5, 6]
piece: list[int] = n_list[:2]
ant: tuple = tuple(n_list)
empty_dict: dict[int, str] = {}
# f-string
greeting: str = input("Enter your name: ")
print(f"Hello, {greeting}!")
# Variable and literal comparison
True is False
False is not None
"True" != None
False is "Right"
one = three
one == two
one != two
one > two
one < two
one >= two
one <= two
# Arithmetic
first_n = int = 5
second_n = int = 10
first_n + second_n
first_n += 2
second_n -= 3
MULTI = first_n * second_n
DIV = second_n / first_n
alpha: list[Any] = ["a", "b", "c", "d", ant, five, n_list, empty_dict]
a_list: list = [five, empty_dict, ant, 5.5, 4_505.8]
# After ':' treats the expression as type instead of var
numbers = {1: five, 2: empty_dict, 3: ant}
a_set = {1, DIV, 2, 4, 5.5}
# String presence changes to default the color for variables
a_tuple = (1, alpha, a_list, 2.5, "string")
# Flow control
for idx, value in enumerate(alpha):
print(idx, value, flush=True)
time.sleep(1)
numbers = {1: 4, 2: 5, 3: 6}
for number, content in numbers.items():
print(f"Entry: {number}\tValue: {content}")
while two < 10:
print(two)
two += 1
five = 5
ten = 10
if five >= ten or ten < 20:
print(five * ten)
# Class creation
class Cat:
"""Dummy text"""
def __init__(self, name: str, race: str, age: int = 8) -> None:
"""Dummy text"""
self.name = name
self.race = race
@property
def output_name(self) -> str:
"""Dummy text"""
print(f"{self.name} is the cat name!")
return self.name
def cats_race(self) -> str:
"""Dummy text"""
print(f"{self.name} is a {self.race}!")
return self.race
bubbles: Cat = Cat("Bubbles", "Mixed")
print(f"Say hello to {bubbles.name}!", end=" ")
bubbles.output_name()
bubbles.cats_race()
with open("test.py", "r") as file:
data: list = file.readlines()
lines: int = len(content)
print(f"Total number of lines is {lines}")