diff --git a/basics.py b/basics.py new file mode 100644 index 0000000..74bb1f1 --- /dev/null +++ b/basics.py @@ -0,0 +1,20 @@ +if True: + print 'hello' + print 'asd' + +# single-line comment + +""" +line 1 +line 2 +line 3 +""" + +name = 'snachodog' +num1 = 5; num2 = 8 + +long_name =\ + "something" + \ + "something else" + +print 'hello world', diff --git a/control_structures.py b/control_structures.py new file mode 100644 index 0000000..d07cd9a --- /dev/null +++ b/control_structures.py @@ -0,0 +1,24 @@ +# if/else/elif +age = 18 + +if age >= 18: + print ('is an adult') +elif age >= 12: + print ("is a young adult") +elif age >= 3: + print ('child') +else: + print ('baby') +# ternary +if age >= 21: + old_enough = True +else: + old_enough = False + + +old_enough = True if age >= 21 else False + +# while +while age < 50: + print("not old enough, current age is " +str(age)) + age += 1 diff --git a/hello.py b/hello.py new file mode 100644 index 0000000..795f1e4 --- /dev/null +++ b/hello.py @@ -0,0 +1 @@ +print ('hello world') diff --git a/strings.py b/strings.py new file mode 100644 index 0000000..081880f --- /dev/null +++ b/strings.py @@ -0,0 +1,25 @@ +# single line +text = 'hello' + +# multi line +multi_line = """line1""" \ + """line2""" \ + """line3""" + +#substrings +name = 'engineer man' +first_name = name[0:8] + +# integer +num1 = 6 + +# float +dec1 = 5.4 + +# conversion to substrings +to_string = str(num1) + +# conversion to integer/float +num_string = '5' +to_int = int(num_string) +to_float = float(num_string)