The document provides an introduction to Python programming, focusing on print and input functions, casting, and strings. It explains the use of parameters in the print function, such as 'sep' and 'end', and introduces the type() function for determining variable data types. Additionally, it covers casting, which allows conversion between different data types using functions like int(), float(), and str().
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views15 pages
Python 3
The document provides an introduction to Python programming, focusing on print and input functions, casting, and strings. It explains the use of parameters in the print function, such as 'sep' and 'end', and introduces the type() function for determining variable data types. Additionally, it covers casting, which allows conversion between different data types using functions like int(), float(), and str().
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15
Computer Programming
Dr. Hilal ARSLAN
Week 3: Introduction to Python
H. Arslan Computer Programming Week 3: Introduction to Python 1 / 32
Outline
•print and input functions
•casting •strings
H. Arslan Computer Programming Week 3: Introduction to Python 2 / 32
print
new line (\n)
• It moves the following character or string to a new line. Tab Comment (\t) • It puts multiple spaces.
Computer Programming print
There are two important parameters:
H. Arslan Computer Programming Week 2: Introduction to Python 4 / 18
Print (sep parameter)
• string inserted between
values, default a space. Print (end parameter)
• string appended after the
last value, default a new line print print output Output: Example
H. Arslan Computer Programming Week 3: Introduction to Python 12 / 32
Example
Computer Programming type()
type() is a built-in function that is used to
return the type of data stored in variables Casting Casting is when you convert a variable value from one type to another. That is, in Python, done with functions like int() or float() or str(). A pattern is that you convert a number as a string • int(): constructs an integer number from an integer literal or a string literal (providing the string represents a whole integer number)