Giter VIP home page Giter VIP logo

python_beginning's Introduction

Python_Beginning

References: (https://drive.google.com/drive/folders/0B7X1ycQalUnyal9yeUx3VW81VDg) (http://www.py4inf.com/code/) #####Basics

for i in [5, 4, 3, 2, 1] :
print i
print 'Blastoff!'

Output:
5
4
3
2
1
Blastoff!
Use of None: variable = None
if variable is None :
variable = value

for letter in 'banana:
 print letter

s = 'Monty Python'
print s[0:4]

>>Mont

print s[6:7]
>>P

print s[6:20]
>>Python

dir("String") // Gives the in-build function list for string

fruit = 'banana'

'n' in fruit

>>True

####List: A linear collection of values that stay in order ####Dictionary: A โ€œbagโ€ of values, each with its own label

Dictionaries have different names in different languages: *Associative Arrays - Perl / PHP *Properties or Map or HashMap - Java *Property Bag - C# / .Net

dictionary = { 'chuck' : 1 , 'fred' : 42','jan': 100}
for aaa,bbb in dictionary.items() :
print aaa, bbb

jan 100
chuck 1
fred 42

counts[word] = counts.get(word,0) + 1

####Tuple: They are non changeable list

#######Difference between list and tuple:

*Tuples are immutable just like strings. 
*There is also a semantic distinction that should guide their usage. 
*Tuples are heterogeneous data structures (i.e., their entries have different meanings), while lists are homogeneous sequences. 
*Tuples have structure, lists have order.
*Tuples: count & index
*Tuples are more efficient, used when the list isn't changing and temporary
>>> (x, y) = (4, 'fred') //tuple has '( )'
>>> print y
fred
>>> (a, b) = (99, 98) //a, b = (99, 98) can be used without the parenthesis
>>> print a
99

*The items() method in dictionaries returns a list of (key, value) tuples

for (k,v) in d.items(): 
print k, v

python_beginning's People

Contributors

angshu-min-js avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.