Skip to content

Instantly share code, notes, and snippets.

@hilava
Last active May 4, 2019 01:45
Show Gist options
  • Save hilava/59ddf9a6a54c16e818d6576cabd18c7a to your computer and use it in GitHub Desktop.
Save hilava/59ddf9a6a54c16e818d6576cabd18c7a to your computer and use it in GitHub Desktop.
Python

Python programming language

Python is a widely used high-level, general-purpose, interpreted, dynamic programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java.

##Python's core philosophy includes:

  • Beautiful is better than ugly
  • Explicit is better than implicit
  • Simple is better than complex
  • Complex is better than complicated
  • Readability counts

###Fun Fact: Youtube was built using Python

###Simple and beautiful code:

def function test(x,y):
    If x < 10 :
      print x
    return y 

###Print a pyramid of height n

def printTriangle():
    n = 10
    for i in range(0 , n):
      s = ' ' * (n-i)
      s = s + '*' * (i*2 - 1)
      print s

printTriangle()

##Data Structures ###Strings characters in quotes. They are immutable data types, means that changing the value of a number data type results in a newly allocated object. ###Numbers Number data types store numeric values. They are immutable data types. ###Lists The list is a versatile datatype available in Python which can be written as a list of comma-separated values (items) between square brackets. The list is indexed starting at 0.

list1 = ['physics', 'chemistry', 1997, 2000]

print list1[0] --> physics

###Dictionary Key-value pairs. Does not maintain order opposed to lists

dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}

print dict['Name'] --> Zara

###Tuples A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are: the tuples cannot be changed unlike lists (cannot sort, append, reverse, etc.) and tuples use parentheses, whereas lists use square brackets. The tuple is indexed starting at 0.

tup1 = ('physics', 'chemistry', 1997, 2000)

print tup1[0] --> physics

Tuples are comparable

(0,1,2)<(5,1,2) --> true

##Resources and links to courses:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment