Difference between revisions of "Python"
From neil.tappsville.com
Jump to navigationJump to search (Created page with " ==== Python version of a perl hash ==== <pre> import collections ; def tree() : return collections.defaultdict(tree) hash = tree() hash'outer_key''inner key' = "v...") |
m |
||
Line 1: | Line 1: | ||
+ | ==+= Data Types ===+ | ||
+ | <pre> | ||
+ | int 1234 | ||
+ | >>> type(1234) | ||
+ | <class 'int'> | ||
+ | float 55.50 | ||
+ | >>> type(55.50) | ||
+ | <class 'float'> | ||
+ | complex | ||
+ | >>> type(6+4j) | ||
+ | <class 'complex'> | ||
+ | string hellow | ||
+ | >>> type("hello") | ||
+ | <class 'str'> | ||
+ | Square list [1,2,3,4] | ||
+ | >>> type([1,2,3,4]) | ||
+ | <class 'list'> | ||
+ | Round tuple (1,2,3,4) | ||
+ | >>> type((1,2,3,4)) | ||
+ | <class 'tuple'> | ||
+ | Curly dict {1:"one", 2:"two", 3:"three"} | ||
+ | >>> type({1:"one", 2:"two", 3:"three"}) | ||
+ | <class 'dict'> | ||
+ | </pre> | ||
+ | |||
==== Python version of a perl hash ==== | ==== Python version of a perl hash ==== |
Revision as of 02:02, 25 November 2019
==+= Data Types ===+
int 1234 >>> type(1234) <class 'int'> float 55.50 >>> type(55.50) <class 'float'> complex >>> type(6+4j) <class 'complex'> string hellow >>> type("hello") <class 'str'> Square list [1,2,3,4] >>> type([1,2,3,4]) <class 'list'> Round tuple (1,2,3,4) >>> type((1,2,3,4)) <class 'tuple'> Curly dict {1:"one", 2:"two", 3:"three"} >>> type({1:"one", 2:"two", 3:"three"}) <class 'dict'>
Python version of a perl hash
import collections ; def tree() : return collections.defaultdict(tree) hash = tree() hash[['outer_key']][['inner key']] = "value" ; if not bool(hash) : print "Hash is empty" ; else : print "Hash has some data"