Created
June 30, 2023 09:59
-
-
Save TomoG29/564a4eed78ed15a66a1c2c2582fc9cf1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val = 5 | |
#----------------------------------------- | |
#------------------ 1 -------------------- | |
#----------------------------------------- | |
if val == 5: | |
print("test1 exe") | |
#結果:test1 exe | |
if val is 5: | |
print("test2 exe") | |
#結果:test2 exe | |
#<>:11: SyntaxWarning: "is" with a literal. Did you mean "=="? | |
if val != 5: | |
print("test3 exe") | |
else: | |
print("test3 error") | |
#結果:test3 error | |
if val is not 5: | |
print("test4 exe") | |
else: | |
print("test4 error") | |
#結果:test4 error | |
#<>:22: SyntaxWarning: "is not" with a literal. Did you mean "!="? | |
sample = 5 | |
print(id(val)) | |
print(id(sample)) | |
if val is sample: | |
print("test5 exe") | |
#結果:140719915243296 | |
# 140719915243296 | |
# test5 exe | |
val_list1 = [1,2] | |
val_list2 = [1,2] | |
print(id(val_list1)) | |
print(id(val_list2)) | |
if val_list1 is val_list2: | |
print("test6 exe") | |
else: | |
print("test6 error") | |
#結果:1735147577536 | |
# 1735112951104 | |
# test6 error | |
if val_list1 == val_list2: | |
print("test7 exe") | |
#結果:test7 exe | |
#----------------------------------------- | |
#------------------ 2 -------------------- | |
#----------------------------------------- | |
if val < 5: | |
print("test8 exe") | |
else: | |
print("test8 error") | |
#結果:test8 error | |
if val <= 5: | |
print("test9 exe") | |
#結果:test9 exe | |
#----------------------------------------- | |
#------------------ 3 -------------------- | |
#----------------------------------------- | |
if (val % 5): | |
print("test10 exe") | |
else: | |
print("test10 error") | |
#結果:test10 error | |
if 0: | |
print("test11 exe") | |
else: | |
print("test11 error") | |
#結果:test11 error | |
if 1: | |
print("test12 exe") | |
#結果:test12 exe | |
#----------------------------------------- | |
#------------------ 4 -------------------- | |
#----------------------------------------- | |
str = "これはサンプルテキストです" | |
if "サンプル" in str: | |
print("test13 exe") | |
#結果:test13 exe | |
if "テスト" not in str: | |
print("test14 exe") | |
#結果:test14 exe | |
list = ["A","B","C"] | |
if "A" in list: | |
print("test15 exe") | |
#結果:test15 exe | |
if "a" in list: | |
print("test16 exe") | |
else: | |
print("test16 error") | |
#結果:test16 error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment