expo.avapose.com

.NET/Java PDF, Tiff, Barcode SDK Library

You now know a lot about Python s basic data types and how to use them to form expressions. As you may remember from 1, computer programs have another important ingredient statements. They re covered in detail in the next chapter.

winforms pdf 417 reader, winforms qr code reader, winforms upc-a reader, winforms data matrix reader, winforms ean 128 reader, winforms ean 13 reader, c# remove text from pdf, c# replace text in pdf, winforms code 39 reader, itextsharp remove text from pdf c#,

Object orientation is not the only development style with which to develop software. The procedural style of programming predates it, and continues to be used in languages such as C. Whereas object orientation dictates that you define concepts and processes as classes from which you can create objects, programming procedurally means you focus on the steps required to complete a task instead, without paying particular attention to how the data is managed. Imagine two developers within a single software development company who are vying to be respected as the most knowledgeable programmer in the company. Capitalizing on the rivalry, their boss issues both of them the same tasks and uses the best code in each case. There s only one difference between the two programmers. One follows the principles of object-oriented development, and the other is a procedural programmer coding without using classes and objects. For a forthcoming project, the boss demands some code that can work out the perimeter and area of various shapes. He says the shapes required are squares and triangles.

The procedural programmer rushes away and quickly comes up with four obvious routines:

7

def perimeter_of_square(side_length) side_length * 4 end def area_of_square(side_length) side_length * side_length end def perimeter_of_triangle(side1, side2, side3) side1 + side2 + side3 end def area_of_triangle(base_width, height) base_width * height / 2 end

Finishing first, the procedural programmer is sure his code will be chosen. The object-oriented programmer takes longer. He recognizes that the specifications might change in future, and that it would be useful to define a Shape class and then create classes that would inherit from Shape. This would mean that if extra features needed to be added to shapes in general, the code would be ready. He submits his initial solution:

A much better way to use the small space at the bottom of the Explanation and Detail slides is to visually cue your audience to the organization of, and current location within, the presentation. For example, if you use a puzzle motif through the presentation, after you sketch the rst puzzle piece on the rst Key Point slide, add a small horizontal bar at the bottom of the subsequent Explanation and Detail slides, and then sketch a small puzzle piece throughout these slides, as shown in Figure 7-16. You ll learn how to set up and apply navigation bars using custom layouts in 8.

y now, I m sure you are getting a bit impatient. All right all these data types are just dandy, but you can t really do much with them, can you Let s crank up the pace a bit. You ve already encountered a couple of statement types (print statements, import statements, assignments). Let s first take a look at some more ways of using these before diving into the world of conditionals and loops. Then, you ll see how list comprehensions work almost like conditionals and loops, even though they are expressions, and finally you ll take a look at pass, del, and exec.

class Shape end class Square < Shape def initialize(side_length) @side_length = side_length end def area @side_length * @side_length end

def perimeter @side_length * 4 end end class Triangle < Shape def initialize(base_width, height, side1, side2, side3) @base_width = base_width @height = height @side1 = side1 @side2 = side2 @side3 = side3 end def area @base_width * @height / 2 end def perimeter @side1 + @side2 + @side3 end end

FIGURE 7-16 The light gray Explanation slides and white Detail slides now include a navigation bar with a

Note This code might seem complex and alien at this time, but we ll be covering the techniques used

As you learn more about Python, you may notice that some aspects of Python that you thought you knew have hidden features just waiting to pleasantly surprise you. Let s take a look at a couple of such nice features in print and import.

   Copyright 2020.