Programming with Python: An Easy to Understand Beginners Guide to Coding with Python by Marc Stanford
Author:Marc Stanford [Stanford, Marc]
Language: eng
Format: mobi, pdf
Publisher: Independently published
Published: 2019-09-25T00:00:00+00:00
⢠Lists, Tuples, Sets, JSON
Python has a great built-in list type named "list". List literals are written within square brackets [ ]. Lists work similarly to strings -- use the len() function and square brackets [ ] to access data, with the first element at index 0.
# List
>>> fruits = [âappleâ, âbananaâ, âcherryâ]
# Add new item into array
>>> fruits.append(âorangeâ) #[âappleâ, âbananaâ, âcherryâ, âorangeâ]
# Pop last item from the aray
>>> fruits.pop() #[âappleâ, âbananaâ, âcherryâ]
# Remove any element from the array
>>> fruits.remove(âbananaâ)
# [âappleâ,âcherryâ]
>>> print(fruits.index(âcherryâ))
# 1
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â and âtuplesâ use parentheses, whereas âlistsâ use square brackets. Creating a âtupleâ is as simple as putting different comma-separated values. Optionally you can also put these comma-separated values between parentheses.
# Tuple
# A tuple is a collection which is ordered and unchangeable.
# In Python tuples are written with round brackets.
>>> thistuple = (âcherryâ, âorangeâ, âkiwiâ, âmelonâ, âmangoâ)
>>> print(thistuple[-4:-1])
# (âorangeâ, âkiwiâ, âmelonâ)
# Join 2 tuples
>>> tuple_number = (1, 2, 3)
>>> print(thistuple[:3] + tuple_number)
# (âappleâ, âbananaâ, âcherryâ, 1, 2, 3)
>>> print(thistuple.index(âcherryâ))
# 2
A âsetâ is an unordered collection of items. Every element is unique (no duplicates) and must be immutable (which cannot be changed). However, the âsetâ itself is mutable. We can add or remove items from it. âSetsâ can be used to perform mathematical âsetâ operations like union, intersection, symmetric difference, etc.
# Set
# A set is a collection which is unordered and unindexed
# In Python sets are written in curly brackets
>>> thisset = {âappleâ, âbananaâ, âcherryâ}
# Add new item to this set
>>> thisset.add(âorangeâ)
# {âorangeâ, âcherryâ, âbananaâ, âappleâ}
>>> thisset.update([âorangeâ, âmangoâ, âgrapesâ])
# {âmangoâ, âorangeâ, âcherryâ, âbananaâ, âgrapesâ,âappleâ}
>>> thisset.remove(âmangoâ)
# {âgrapesâ, âcherryâ, âappleâ, âorangeâ,âbananaâ}
>>> list1 = [11,12,22,23,11,22,44,55,66,23]
>>> print(set(list1))
# {66,11,12,44,55,22,23}
>>> set2 = {1,3,4,5}
>>> print(thisset.union(set2))
# {1, âappleâ, âbananaâ, 3, 4, âorangeâ, âgrapesâ, âcherryâ, 5}
âJSONâ (Java Script Object Notation) is a popular data format used for representing structured data. It's common to transmit and receive data between a server and web application in âJSONâ format. In Python, âJSONâ exists as a string.
# JSON
>>> import json
# some JSON:
>>> x = â{ânameâ, âJohnâ, âageâ:30, âcityâ:âNew Yorkâ}â
# parse x
>>> y = json.loads(x)
# the result is a Python dictionary:
>>> print(y[âageâ])
# 30
⢠Datetime
Download
Programming with Python: An Easy to Understand Beginners Guide to Coding with Python by Marc Stanford.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12585)
Hello! Python by Anthony Briggs(9920)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9799)
The Mikado Method by Ola Ellnestam Daniel Brolund(9782)
Dependency Injection in .NET by Mark Seemann(9343)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(9299)
Hit Refresh by Satya Nadella(8826)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8305)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7786)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7768)
Grails in Action by Glen Smith Peter Ledbrook(7700)
The Kubernetes Operator Framework Book by Michael Dame(7666)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7562)
Exploring Deepfakes by Bryan Lyon and Matt Tora(7455)
Practical Computer Architecture with Python and ARM by Alan Clements(7378)
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(7361)
Robo-Advisor with Python by Aki Ranin(7335)
Building Low Latency Applications with C++ by Sourav Ghosh(7242)
Svelte with Test-Driven Development by Daniel Irvine(7207)
