Skip to main content

1-4 Basics of Python

Updated 1 min readMarkdown
Part of seriesPython

Type() is used to identify a type of a variable.

Types of variables

  1. Int

    a = 5
    type(a)
    
    int
    
  2. Float

    b = 5.0
    type(b)
    
    float
    
  3. Str

    c = 'Hello'
    type(c)
    
    str
    
  4. List

    list1 = [1, 2, 3, 4, 5]
    list2 = ['a', 'b', 'c', 'd', 'e']
    print(type(list1))
    print(type(list2))
    
    <class 'list'>
    <class 'list'>
    

variables should be in the square brackets.

Indexing: used to select a variable in a specific order. The order number starts with 0.

list = ['a', 'k', 'j', 'b', 's', 'v', '!']
list[0]
'a'

Append: used to add another variable to the list.

list_1 = [1, 2, 3, 4, 5]
list_1.append(155)
list_1
[1, 2, 3, 4, 5, 155]

Extend: used to merge one list with another list.

list_2 = ['a', 'b', 'c']
list_1.extend(list_2)
print(list_1)
[1, 2, 3, 4, 5, 155, 'a', 'b', 'c']

No comments yet. Be the first to comment.

More from this blog