MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Python/comments/ivdvef/powershell_vs_python_reference/g5vq7yo/?context=3
r/Python • u/pmz • Sep 18 '20
14 comments sorted by
View all comments
2
A few essential things that are left out:
PS has switch/case conditional statements whereas python does not. You can approximate the functionality with if/else statements
PS example:
switch ($var) { case1 { $true_condition1 } case2 { $true_condition2 } default { $nothing_matched } }
Python example:
if var == case1: true_condition1 elif var == case2: true_condition2 else: nothing_matched
PS doesn't have the slice vector notation capability like python (wish it did)
# getting elements 0-5 @($array[0],$array[1],$array[2],$array[3],$array[4],$array[5])
# getting elements 0-5 array[:5]
PS's feature set can be extended by using inline C#
4 u/[deleted] Sep 19 '20 In Python, you can emulate switch cases more effectively than if/else statements using a dictionary acting as a dispatch table.Because functions in Python are objects, they can be stored and called from anywhere an object could be.Meaning I can do things liketable = { case_1: true_condition }def true_condition(): print(“Hello World”) 1 u/i5513 Sep 19 '20 But switch on powershell is like awk on Linux, It is not as simple like other switch statements in others program languages
4
In Python, you can emulate switch cases more effectively than if/else statements using a dictionary acting as a dispatch table.
Because functions in Python are objects, they can be stored and called from anywhere an object could be.
Meaning I can do things like
table = { case_1: true_condition }
def true_condition(): print(“Hello World”)
1 u/i5513 Sep 19 '20 But switch on powershell is like awk on Linux, It is not as simple like other switch statements in others program languages
1
But switch on powershell is like awk on Linux, It is not as simple like other switch statements in others program languages
2
u/WadeEffingWilson Sep 19 '20 edited Sep 19 '20
A few essential things that are left out:
PS has switch/case conditional statements whereas python does not. You can approximate the functionality with if/else statements
PS example:
Python example:
PS doesn't have the slice vector notation capability like python (wish it did)
PS example:
Python example:
PS's feature set can be extended by using inline C#