From 2a91c4c3ed0d25f7c4a9bbe13afad8e348ea25af Mon Sep 17 00:00:00 2001 From: askhat zhuman Date: Thu, 18 Nov 2021 22:08:54 +0600 Subject: [PATCH 1/2] adding first commit to my python tutorial repo --- python_sandbox_starter/lists.py | 21 +++++++++++++++++++++ python_sandbox_starter/strings.py | 13 +++++++++++++ python_sandbox_starter/tuples_sets.py | 6 +++++- python_sandbox_starter/variables.py | 11 +++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/python_sandbox_starter/lists.py b/python_sandbox_starter/lists.py index 6cd3bbd..0a4c68b 100644 --- a/python_sandbox_starter/lists.py +++ b/python_sandbox_starter/lists.py @@ -1 +1,22 @@ # A List is a collection which is ordered and changeable. Allows duplicate members. + +# create list +numbers = [1, 2, 3, 4, 5, 6] +fruits = ['apples', 'oranges', 'grapes', 'pears'] + +#use constructor +numbers2 = list((9, 8, 7, 6, 5, 4, 3)) + +print(numbers, numbers2) +print(len(fruits)) +print(fruits[2]) + +#append item to list +fruits.append('mangoes') + +#insert into position of list +fruits.insert(0, 'strawberries') + +# remove item from list +fruits.remove(fruits[2]) +print(fruits) \ No newline at end of file diff --git a/python_sandbox_starter/strings.py b/python_sandbox_starter/strings.py index 0942500..dbeb3bc 100644 --- a/python_sandbox_starter/strings.py +++ b/python_sandbox_starter/strings.py @@ -1,6 +1,19 @@ # Strings in python are surrounded by either single or double quotation marks. Let's look at string formatting and some string methods +name = 'Askhat' +age = 37 + +# Concatenate +print('Hello my name is '+ name + ' i`am ' + str(age) +'.') # String Formatting +# arguments by position +print('my name is {name} i am {age}'.format(name = name, age = age)) + +#F-Strings +print(f'hello, my name is {name} and i am {age}') + # String Methods +s = 'hello, world!' +print(s.capitalize()) diff --git a/python_sandbox_starter/tuples_sets.py b/python_sandbox_starter/tuples_sets.py index 90d2fc4..40c41cf 100644 --- a/python_sandbox_starter/tuples_sets.py +++ b/python_sandbox_starter/tuples_sets.py @@ -1,5 +1,9 @@ # A Tuple is a collection which is ordered and unchangeable. Allows duplicate members. +fruits = ('apples', 'oranges', 'grapes') +fruits2 = ('apples',) - +print(fruits2, type(fruits2)) +print(fruits[2]) +fruits[0] = 'strawberry' # A Set is a collection which is unordered and unindexed. No duplicate members. diff --git a/python_sandbox_starter/variables.py b/python_sandbox_starter/variables.py index 7ffc3e4..4122765 100644 --- a/python_sandbox_starter/variables.py +++ b/python_sandbox_starter/variables.py @@ -13,3 +13,14 @@ - Must start with a letter or an underscore - Can have numbers but can not start with one """ +x=1 +y = 2.1 +name = "askhat" +is_cool = True + +x, y, name, is_cool = (1, 2.5, 'askhat', True) +a = x + y + +print(x, y, name, is_cool, a) + +print(type(y)) \ No newline at end of file From 30fb0fbd12fb49d7e5840f3de0d95d6fc6c963ce Mon Sep 17 00:00:00 2001 From: askhat zhuman Date: Thu, 18 Nov 2021 23:15:29 +0600 Subject: [PATCH 2/2] second commit --- python_sandbox_starter/tuples_sets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python_sandbox_starter/tuples_sets.py b/python_sandbox_starter/tuples_sets.py index 40c41cf..48c9ada 100644 --- a/python_sandbox_starter/tuples_sets.py +++ b/python_sandbox_starter/tuples_sets.py @@ -7,3 +7,4 @@ print(fruits[2]) fruits[0] = 'strawberry' # A Set is a collection which is unordered and unindexed. No duplicate members. +