feat: format codes

This commit is contained in:
2025-09-03 22:54:00 +08:00
parent 3cbd697e60
commit afe5995412
4 changed files with 13 additions and 5 deletions

View File

@@ -8,6 +8,7 @@ class Person():
def __repr__(self): def __repr__(self):
return repr((self.name, self.age)) return repr((self.name, self.age))
people = [ people = [
Person("tom", 22), Person("tom", 22),
Person("jack", 11), Person("jack", 11),

View File

@@ -2,16 +2,20 @@
do_add = lambda a, b: a + b do_add = lambda a, b: a + b
def do_add_2(a, b): def do_add_2(a, b):
return a + b return a + b
def incr(base, inc=1): def incr(base, inc=1):
return base + inc return base + inc
def var_args(first_arg="first", *args): def var_args(first_arg="first", *args):
print("fist arg:", first_arg) print("fist arg:", first_arg)
print("rest args:", args) print("rest args:", args)
if __name__ == "__main__": if __name__ == "__main__":
print("1 + 2 =", do_add(1, 2)) print("1 + 2 =", do_add(1, 2))
print("1 + 2 =", do_add_2(1, 2)) print("1 + 2 =", do_add_2(1, 2))

View File

@@ -3,6 +3,7 @@
def is_leap_year(year: int): def is_leap_year(year: int):
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0 return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
if __name__ == "__main__": if __name__ == "__main__":
print(1582, is_leap_year(1582)) print(1582, is_leap_year(1582))
print(2000, is_leap_year(2000)) print(2000, is_leap_year(2000))

View File

@@ -2,6 +2,7 @@
import socket import socket
import ssl import ssl
def get_server_certificate(hostname, port=443): def get_server_certificate(hostname, port=443):
# context = ssl.create_default_context() # context = ssl.create_default_context()
context = ssl._create_unverified_context() context = ssl._create_unverified_context()
@@ -11,6 +12,7 @@ def get_server_certificate(hostname, port=443):
cert = ssock.getpeercert() cert = ssock.getpeercert()
return cert return cert
# not success, but why? # not success, but why?
if __name__ == "__main__": if __name__ == "__main__":
certificate = get_server_certificate("hatter.ink") certificate = get_server_certificate("hatter.ink")