Skip to content

Instantly share code, notes, and snippets.

@Nahiduzzaman
Last active May 24, 2017 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nahiduzzaman/8b86acbce085dcc1395f7743456404da to your computer and use it in GitHub Desktop.
Save Nahiduzzaman/8b86acbce085dcc1395f7743456404da to your computer and use it in GitHub Desktop.
Python Variable Types:
counter = 100 # An integer assignment
miles = 1000.0 # A floating point
name = "John" # A string
print counter
print miles
print name
-------------------------------output------------------------------
100
1000.0
John
Multiple Assignment
Python allows you to assign a single value to several variables simultaneously. For example −
a = b = c = 1
a,b,c = 1,2,"john"
Standard Data Types
The data stored in memory can be of many types. For example, a person's age is stored as a numeric value and his or her address is stored as alphanumeric characters. Python has various standard data types that are used to define the operations possible on them and the storage method for each of them.
Python has five standard data types −
Numbers
String
*List
*Tuple
*Dictionary
------------------------Delete------------------------------
var1 = 1
var2 = 10
del var1
print var1 //error undefined
------------------Python Strings---------------------------------
str = 'Hello World!'
print str # Prints complete string
print str[0] # Prints first character of the string
print str[2:5] # Prints characters starting from 3rd to 5th
print str[2:] # Prints string starting from 3rd character
print str * 2 # Prints string two times
print str + "TEST" # Prints concatenated string
-------------------------- *range ---------------------------
from __future__ import print_function //import print function
if __name__ == '__main__': // Hackerrnak
n = int(raw_input());
print(*range(1,n+1), sep=""); //* makes the function iterative.
------------------------- take input integers seperated by space ------------------------------
Following code will take 5
numCast = 5 // How many input steps?
for i in range(numCust):
size, price = map(int, raw_input().split())
-------------------Hackerrank collection shoes size price -------------------------------------
# pylint: disable=invalid-name
import collections
numShoes = int(raw_input())
shoes = collections.Counter(map(int, raw_input().split()))
numCust = int(raw_input())
income = 0
#this line returns counter like "Counter({8: 1, 2: 1, 3: 1, 5: 1, 6: 1})" so "shoes[6] = 1"
#print shoes
for i in range(numCust):
size, price = map(int, raw_input().split())
if shoes[size]:
income += price #if shoes size available increase income by price
shoes[size] -= 1 # and decrease the current number of size as it is purchased
print income
Date: 24-05-2017|11:00PM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment