Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Learn Python Programming
  • Toc
  • feedback
Learn Python Programming

Learn Python Programming

By : Fabrizio Romano, Fabrizio Romano, Heinrich Kruger, Heinrich Kruger
5 (1)
close
Learn Python Programming

Learn Python Programming

5 (1)
By: Fabrizio Romano, Fabrizio Romano, Heinrich Kruger, Heinrich Kruger

Overview of this book

Learn Python Programming, Fourth Edition, provides a comprehensive, up-to-date introduction to Python programming, covering fundamental concepts and practical applications. This edition has been meticulously updated to include the latest features from Python versions 3.9 to 3.12, new chapters on type hinting and CLI applications, and updated examples reflecting modern Python web development practices. This Python book empowers you to take ownership of writing your software and become independent in fetching the resources you need. By the end of this book, you will have a clear idea of where to go and how to build on what you have learned from the book. Through examples, the book explores a wide range of applications and concludes by building real-world Python projects based on the concepts you have learned. This Python book offers a clear and practical guide to mastering Python and applying it effectively in various domains, such as data science, web development, and automation.
Table of Contents (20 chapters)
close
18
Other Books You May Enjoy
19
Index

Python approach to types

Python is both a strongly typed and a dynamically typed language.

Strongly typed means that Python does not allow implicit type conversions that could lead to unexpected behaviors. Consider the following php code:

<?php
$a = 2;
$b = "2";
echo $a + $b; // prints: 4
?>

In php, variables are prepended with a $ sign. In the above code, we set $a to the integer number 2, and $b to the string "2". To add them together, php performs an implicit conversion of $b, from string to integer. This is referred to as type juggling. This might seem a convenient feature, but the fact that php is weakly typed has the potential to lead to bugs in the code. If we tried to do the same in Python, the result would be much different:

# example.strongly.typed.py
a = 2
b = "2"
print(a + b)

Running the above produces:

$ python ch12/example.strongly.typed.py
Traceback (most recent call last):
  File "ch12/example.strongly...
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete