Python is a formal programming language that was designed for specific computational applications. Formal languages like Python have strict syntax rules for tokens and structure and are unambiguous, unlike natural languages. The first program commonly written in a new programming language is "Hello, World!" which simply displays that text. In Python, this is done using the print statement or function to output "Hello, World!" to the screen without any other meaning.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
85 views
Python Formal and Normal Languages
Python is a formal programming language that was designed for specific computational applications. Formal languages like Python have strict syntax rules for tokens and structure and are unambiguous, unlike natural languages. The first program commonly written in a new programming language is "Hello, World!" which simply displays that text. In Python, this is done using the print statement or function to output "Hello, World!" to the screen without any other meaning.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8
Python Programming
NATURAL AND FORMAL LANGUAGES
Formal and natural languages Natural languages are the languages people speak, such as English, Spanish, and French. They were not designed by people, they evolved naturally. Formal languages are languages that are designed by people for specific applications. For example, the notation that mathematicians use is a formal language that is particularly good at denoting relationships among numbers and symbols. Chemists use a formal language to represent the chemical structure of molecules. Formal Languages
Programming languages are formal languages
that have been designed to express computations. Formal languages tend to have strict rules about syntax. For example, 3 + 3 = 6 is a syntactically correct mathematical statement, but 3+ = 3$6 is not. H2O is a syntactically correct chemical formula, but 2Zz is not. Formal Languages
Syntax rules come in two flavors, pertaining to
tokens and structure. Tokens are the basic elements of the language, such as words, numbers, and chemical elements. One of the problems with 3+ = 3$6 is that $ is not a legal token in mathematics. The second type of syntax rule pertains to the structure of a statement; that is, the way the tokens are arranged. The statement 3+ = 3 is illegal because even though + and = are legal tokens, it can’t have one right after the other. Differences-Ambiguity Ambiguity (unclear or not clear) : Natural languages are full of ambiguity, which people deal with by using contextual clues and other information. Formal languages are designed to be nearly or completely unambiguous, which means that any statement has exactly one meaning, regardless of context. Differences-Redundancy and Literalness Redundancy (unnecessary use of more than one word): In order to make up for ambiguity and reduce misunderstandings, natural languages employ lots of redundancy. As a result, they are often verbose. Formal languages are less redundant and more concise. Literalness (understanding exact words and rather than un extended words): Natural languages are full of idiom and metaphor. If I say, “The penny dropped,” there is probably no penny and nothing dropping. Formal languages mean exactly what they say. The First program Traditionally, the first program written in a new language is called “Hello, World!” because all it does is display the words “Hello,World!”.
In Python, it looks like this:
print 'Hello, World!'
The First program This is an example of a print statement, which doesn’t actually print anything on paper. It displays a value on the screen. In this case, the result is the words Hello, World! The quotation marks mark the beginning and end of the text to be displayed but they don’t appear in the result. In Python 3, the syntax is slightly different: print ('Hello, World!') The parentheses indicate that print is a function.