Grants-Web-Net
Details
Category: Example
Published: 03 September 2014
Hits: 1824

Hello World

{module Programming}

{source}
<!-- You can place html anywhere within the source tags -->

<pre class="brush:php;">
&lt;?php
$example = range(0, 9);
foreach ($example as $value)
{
echo $value;
}
?&gt
</pre>



<script language="javascript" type="text/javascript">
    // You can place JavaScript like this

</script>
<?php


// You can place PHP like this

?>
{/source}

Details
Category: Example
Published: 23 August 2014
Hits: 15009

Python 3.4

{article Python Content}{title} {text}{/article}

Examples Python 3.4

Examples Python 3.4

bubblesort( ) Introspection primes Sep in Python
Comparison Operators Logical Operators print( ) Tabs or Spaces
Equality Operators math.sqrt( ) Prints a newline UserDict
exit ( ) Modules python version ! exclamation mark
help() os.chdir(' ') ::Change directory quickSort(list) __getattr__
input() Function pass statement range() Function __setitem__
execute a file in python shell IDLE's Python operators Math Order of operations pip install
list Private Variables In Python mode Escape Characters: \
String Formatting Operator: % Virtual Environments IDLE changing working directory Wheel
pip to install pip Regular Expressions - Python
Dive Into Python Python Table of Content
Details
Category: Example
Published: 25 July 2014
Hits: 1985

{article Examples__Python 3.4 }{title} {text}{/article}

NameError: name 'raw_input' is not defined

In python 3.x, there is only one function to get user inputs and that is called input, which is equivalent to Python 2.7's raw_input.

input([prompt])

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. Example:

>>> s = input('--> ')
--> Monty Python's Flying Circus
>>> s
"Monty Python's Flying Circus"

{source}
<!-- You can place html anywhere within the source tags -->

<pre class="brush:py;">
>>> s = input('--> ')
--> Monty Python's Flying Circus
>>> s
"Monty Python's Flying Circus"
>>>
</pre>

<script language="javascript" type="text/javascript">
    // You can place JavaScript like this

</script>
<?php
    // You can place PHP like this

?>
{/source}

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> fname = input('Enter your name: ')
Enter your name: Bill
>>> print('Hello', '!')
Hello !
>>> print('Hello', fname, '!')
Hello Bill !
>>>

{source}
<!-- You can place html anywhere within the source tags -->

<pre class="brush:py;">

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> fname = input('Enter your name: ')
Enter your name: Bill
>>> print('Hello', '!')
Hello !
>>> print('Hello', fname, '!')
Hello Bill !
>>>

</pre>

<script language="javascript" type="text/javascript">
    // You can place JavaScript like this

</script>
<?php
    // You can place PHP like this

?>
{/source}

>>> num1 = int(input('Enter a number: '))
Enter a number: 2
>>> num2 = int(input('Enter a number: '))
Enter a number: 2
>>> print(num1 + num2)
4
>>>

{source}
<!-- You can place html anywhere within the source tags -->

<pre class="brush:py;">

>>> num1 = int(input('Enter a number: '))
Enter a number: 2
>>> num2 = int(input('Enter a number: '))
Enter a number: 2
>>> print(num1 + num2)
4
>>>

</pre>

<script language="javascript" type="text/javascript">
    // You can place JavaScript like this

</script>
<?php
    // You can place PHP like this

?>
{/source}

Details
Category: Example
Published: 25 July 2014
Hits: 1807

{article Examples__Python 3.4 }{title} {text}{/article}

The range type represents an immutable sequence of numbers and is commonly used for looping a specific number of times in for loops.

class range(stop)

class range(start, stop[, step])

The arguments to the range constructor must be integers (either built-in int or any object that implements the __index__ special method). If the step argument is omitted, it defaults to 1. If the start argument is omitted, it defaults to 0. If step is zero, ValueError is raised.

For a positive step, the contents of a range r are determined by the formula r[i] = start + step*i where i >= 0 and r[i] < stop.

For a negative step, the contents of the range are still determined by the formula r[i] = start + step*i, but the constraints are i >= 0 and r[i] > stop.

A range object will be empty if r[0] does not meet the value constraint. Ranges do support negative indices, but these are interpreted as indexing from the end of the sequence determined by the positive indices.

Ranges containing absolute values larger than sys.maxsize are permitted but some features (such as len()) may raise OverflowError.

class range(stop)

class range(start, stop[, step])


class range(stop)

>>> for i in range(5):
print(i)


0
1
2
3
4


class range(start, stop)

>>> range(5, 10)
[5, 6, 7, 8, 9]


class range(start, stop[, step])

>>> range(0, 10, 3)
[0, 3, 6, 9]



>>> range(-10, -100, -30)
[-10, -40, -70]



>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
>>> for i in range(len(a)):
print(i, a[i])

(0, 'Mary')
(1, 'had')
(2, 'a')
(3, 'little')
(4, 'lamb')



>>> print(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]



>>> list(range(5))
[0, 1, 2, 3, 4]



>>>

{source}
<!-- You can place html anywhere within the source tags -->
<pre class="brush:py;">
class range(stop)

>>> for i in range(5):
    print(i)


0
1
2
3
4
class range(start, stop)

>>> range(5, 10)
[5, 6, 7, 8, 9]
class range(start, stop[, step])

>>> range(0, 10, 3)
[0, 3, 6, 9]


>>> range(-10, -100, -30)
[-10, -40, -70]


>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
>>> for i in range(len(a)):
        print(i, a[i])

    (0, 'Mary')
(1, 'had')
(2, 'a')
(3, 'little')
(4, 'lamb')


>>> print(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


>>> list(range(5))
[0, 1, 2, 3, 4]

</pre>

<script language="javascript" type="text/javascript">
    // You can place JavaScript like this

</script>
<?php
    // You can place PHP like this

?>
{/source}

Details
Category: Example
Published: 24 July 2014
Hits: 1678

{article Examples__Python 3.4 }{title} {text}{/article}

The print statement has been replaced with a print() function,

print()

{source}
<!-- You can place html anywhere within the source tags -->
<pre class="brush:py;">
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print()

>>>

</pre>

<script language="javascript" type="text/javascript">
    // You can place JavaScript like this

</script>
<?php
    // You can place PHP like this

?>
{/source}

Details
Category: Example
Published: 24 July 2014
Hits: 1611

{article Examples__Python 3.4 }{title} {text}{/article}

type a prompt

exit ()

or you can press ctrl+d

Details
Category: Example
Published: 08 July 2014
Hits: 1792

{article Examples__Python 3.4 }{title} {text}{/article}

 

Removing the space at the end of its arguments

You can also customize the separator between items, e.g.:

ride = "Airplane"
print("I like to ride in a ", ride, '!');




To avoid that space you will need to explicitly specify the 'sep' keyword.

print ("I like to ride in a ", ride, "!", sep="") # Note the explicit sep=""

output = "".join(["I like to ride in a ",ride,"!"])

print(output)

 

 

{source}
<!-- You can place html anywhere within the source tags -->
<pre class="brush:py;">
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ride = "Airplane"
>>> print("I like to ride in a ", ride, '!'); #To avoid that space you will need to explicitly specify the 'sep' keyword.
I like to ride in a Airplane !
>>> print ("I like to ride in a ", ride, "!", sep="") # Note the explicit sep=""
I like to ride in a Airplane!
>>> output = "".join(["I like to ride in a ",ride,"!"])
>>> print(output)
I like to ride in a Airplane!
>>> print ("Note NO space between Airplane!")
Note NO space between Airplane!
>>>


</pre>

<script language="javascript" type="text/javascript">
    // You can place JavaScript like this

</script>
<?php
    // You can place PHP like this

?>
{/source}

Details
Category: Example
Published: 30 July 2014
Hits: 1736

{article Examples__Python 3.4 }{title} {text}{/article}

Modules

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable __name__. For instance, use your favorite text editor to create a file called fibo.py in the current directory with the following contents:

A module allows you to logically organize your Python code. Grouping related code into a module makes the code easier to understand and use. A module is a Python object with arbitrarily named attributes that you can bind and reference. Simply, a module is a file consisting of Python code. A module can define functions, classes, and variables. A module can also include runnable code.

Modules Names

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability.

Details
Category: Example
Published: 30 July 2014
Hits: 1686

{article Examples__Python 3.4 }{title} {text}{/article}

Spaces are the preferred indentation method.

Tabs should be used solely to remain consistent with code that is already indented with tabs.

Python 3 disallows mixing the use of tabs and spaces for indentation.

Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.

When invoking the Python 2 command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended!

Details
Category: Example
Published: 31 July 2014
Hits: 1707

{article Examples__Python 3.4 }{title} {text}{/article}

Introspection is code looking at other modules and functions in memory as objects, information about them and manipulating them.

Details
Category: Example
Published: 31 July 2014
Hits: 1588

{article Examples__Python 3.4 }{title} {text}{/article}

!= means not equal to.

  1. Primes
  2. print( )
  3. math.sqrt( )
  4. bubblesort( )
  5. quickSort(list)
  6. help( )
  7. pass statement
  8. os.chdir(' ') ::Change directory
  9. python version
  10. Logical Operators